Dynatrace OneAgent SDK for C/C++  1.7.1.1
onesdk_string.h
Go to the documentation of this file.
1 /*
2  Copyright 2017-2018 Dynatrace LLC
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  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #ifndef ONESDK_STRING_H_INCLUDED
18 #define ONESDK_STRING_H_INCLUDED
19 
24 /*========================================================================================================================================*/
25 
26 #include "onesdk/onesdk_common.h"
27 
28 #include <string.h> /* for strlen */
29 
30 #if defined(_WIN32)
31 #include <wchar.h> /* for wcslen */
32 #endif
33 
34 /*========================================================================================================================================*/
35 
41 /*========================================================================================================================================*/
42 
44 typedef uint16_t onesdk_ccsid_t;
45 
59 typedef struct onesdk_string {
60  void const* data;
64 
65 /*========================================================================================================================================*/
66 
79 #define ONESDK_CCSID_NULL ((onesdk_ccsid_t) 0)
80 
81 #define ONESDK_CCSID_ASCII ((onesdk_ccsid_t) 367)
82 #define ONESDK_CCSID_ISO8859_1 ((onesdk_ccsid_t) 819)
83 #define ONESDK_CCSID_UTF8 ((onesdk_ccsid_t)1209)
84 #define ONESDK_CCSID_UTF16_BE ((onesdk_ccsid_t)1201)
85 #define ONESDK_CCSID_UTF16_LE ((onesdk_ccsid_t)1203)
90 #if defined(ONESDK_BUILD_DOC)
91 #define ONESDK_CCSID_UTF16_NATIVE
92 #endif
93 
94 #if defined(ONESDK_LITTLE_ENDIAN)
95 #define ONESDK_CCSID_UTF16_NATIVE ONESDK_CCSID_UTF16_LE
96 #endif
97 
98 #if defined(ONESDK_BIG_ENDIAN)
99 #define ONESDK_CCSID_UTF16_NATIVE ONESDK_CCSID_UTF16_BE
100 #endif
101 
104 /*========================================================================================================================================*/
105 
119 ONESDK_DEFINE_INLINE_FUNCTION(onesdk_string_t) onesdk_str(void const* data, onesdk_size_t byte_length, onesdk_ccsid_t ccsid) {
120  onesdk_string_t str = { NULL, 0, 0 };
121  str.data = data;
122  str.byte_length = byte_length;
123  str.ccsid = ccsid;
124  return str;
125 }
126 
138 ONESDK_DEFINE_INLINE_FUNCTION(onesdk_string_t) onesdk_bytestr(char const* data, onesdk_ccsid_t ccsid) {
139  return onesdk_str(data, data ? ((onesdk_size_t)strlen(data)) : 0, ccsid);
140 }
141 
149 ONESDK_DEFINE_INLINE_FUNCTION(onesdk_string_t) onesdk_asciistr(char const* data) {
150  return onesdk_bytestr(data, ONESDK_CCSID_ASCII);
151 }
152 
160 ONESDK_DEFINE_INLINE_FUNCTION(onesdk_string_t) onesdk_utf8str(char const* data) {
161  return onesdk_bytestr(data, ONESDK_CCSID_UTF8);
162 }
163 
170 ONESDK_DEFINE_INLINE_FUNCTION(onesdk_string_t) onesdk_nullstr(void) {
171  return onesdk_str(0, 0, ONESDK_CCSID_NULL);
172 }
173 
174 #if (defined(_WIN32) && defined(ONESDK_CCSID_UTF16_NATIVE)) || defined(ONESDK_BUILD_DOC)
175 
190 ONESDK_DEFINE_INLINE_FUNCTION(onesdk_string_t) onesdk_wstr(wchar_t const* data) {
191  return onesdk_str(data, data ? ((onesdk_size_t)wcslen(data) * 2) : 0, ONESDK_CCSID_UTF16_NATIVE);
192 }
193 
194 #endif
195 
198 /*========================================================================================================================================*/
199 
202 /*========================================================================================================================================*/
203 
204 #endif /* ONESDK_STRING_H_INCLUDED */
Defines common types/constants/macros. Applications should not include this file directly.
#define ONESDK_CCSID_UTF8
CCSID value for UTF-8 encoded text.
Definition: onesdk_string.h:83
#define ONESDK_CCSID_ASCII
CCSID value for 7 bit ASCII text.
Definition: onesdk_string.h:81
onesdk_string_t onesdk_utf8str(char const *data)
Creates a onesdk_string_t for a UTF-8 string.
Definition: onesdk_string.h:160
onesdk_string_t onesdk_str(void const *data, onesdk_size_t byte_length, onesdk_ccsid_t ccsid)
Creates a onesdk_string_t.
Definition: onesdk_string.h:119
onesdk_string_t onesdk_wstr(wchar_t const *data)
Creates a onesdk_string_t for a wchar_t UTF-16 string using the native endianness.
Definition: onesdk_string.h:190
onesdk_string_t onesdk_asciistr(char const *data)
Creates a onesdk_string_t for an ASCII string.
Definition: onesdk_string.h:149
#define ONESDK_CCSID_UTF16_NATIVE
CCSID for UTF-16 text with the native endianness (either ONESDK_CCSID_UTF16_LE or ONESDK_CCSID_UTF16_...
Definition: onesdk_string.h:91
Represents a reference to string data in a user specified encoding.
Definition: onesdk_string.h:59
onesdk_string_t onesdk_nullstr(void)
Creates a onesdk_string_t designating a "null string".
Definition: onesdk_string.h:170
onesdk_string_t onesdk_bytestr(char const *data, onesdk_ccsid_t ccsid)
Creates a onesdk_string_t for a byte string.
Definition: onesdk_string.h:138
void const * data
Pointer to the beginning of the string data. May be NULL if byte_length is zero.
Definition: onesdk_string.h:60
onesdk_ccsid_t ccsid
Specifies the encoding of the string data.
Definition: onesdk_string.h:62
size_t onesdk_size_t
Unsigned integer type used for sizes (e.g. array sizes) and counts.
Definition: onesdk_config.h:220
#define ONESDK_CCSID_NULL
Special "NULL" CCSID value.
Definition: onesdk_string.h:79
onesdk_size_t byte_length
The length of the buffer pointed to by data, in bytes.
Definition: onesdk_string.h:61
uint16_t onesdk_ccsid_t
Used to store CCSID values.
Definition: onesdk_string.h:44