Ion C
C library for Ion
Loading...
Searching...
No Matches
ion_string.h
Go to the documentation of this file.
1/*
2 * Copyright 2011-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at:
7 *
8 * http://aws.amazon.com/apache2.0/
9 *
10 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
12 * language governing permissions and limitations under the License.
13 */
14
28#ifndef ION_STRING_H_
29#define ION_STRING_H_
30
31#include <string.h>
32#include "ion_platform_config.h"
33#include "ion_types.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
40{
41
42 int32_t length;
45 BYTE *value;
46};
47
48#define DEFAULT_STRING_LENGTH 8
49// WAS: #define INIT_ION_STRING(x) memset((x), 0, sizeof(*(x)))
50// WAS: #define ION_STRING_INIT(x) memset((x), 0, sizeof(*(x)))
51#define ION_STRING_INIT(x) (x)->length = 0; (x)->value = NULL
52#define ION_STRING_ASSIGN(dst, src) (dst)->length = (src)->length; (dst)->value = (src)->value
53#define ION_STRING_IS_NULL(x) ((x) == NULL || ((x)->value == NULL))
54#define ION_STRING_EQUALS(x, y) (((x) == (y)) || (((x)->length == (y)->length) && (memcmp((x)->value, (y)->value, (x)->length) == 0)))
55#define ION_STRING_CHAR_AT(str, ii) ((ii) < (str)->length ? (str)->value[ii] : -1)
56
57ION_API_EXPORT void ion_string_init (ION_STRING *str);
58ION_API_EXPORT void ion_string_assign (ION_STRING *dst, ION_STRING *src); // assigns contents but doesn't move bytes
59ION_API_EXPORT ION_STRING *ion_string_assign_cstr (ION_STRING *str, char *val, SIZE len);
60ION_API_EXPORT char *ion_string_strdup (ION_STRING *p_ionstring);
61ION_API_EXPORT iERR ion_string_copy_to_owner(hOWNER owner, ION_STRING *dst, ION_STRING *src);
62
70ION_API_EXPORT int ion_string_get_length(ION_STRING *str);
71
75ION_API_EXPORT BYTE ion_string_get_byte(ION_STRING *str, int idx);
76
86ION_API_EXPORT BYTE *ion_string_get_bytes(ION_STRING *str);
87
88ION_API_EXPORT BOOL ion_string_is_null (ION_STRING *str);
89ION_API_EXPORT BOOL ion_string_is_equal (ION_STRING *str1, ION_STRING *str2);
90
91#ifdef __cplusplus
92}
93#endif
94#endif /* ION_STRING_H_ */
ION_API_EXPORT BYTE * ion_string_get_bytes(ION_STRING *str)
ION_API_EXPORT int ion_string_get_length(ION_STRING *str)
ION_API_EXPORT BYTE ion_string_get_byte(ION_STRING *str, int idx)
Definition ion_string.h:40
int32_t length
Definition ion_string.h:42
BYTE * value
Definition ion_string.h:45