MySQL 8.3.0
Source Code Documentation
mysql_string.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is also distributed with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have included with MySQL.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License, version 2.0, for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef MYSQL_STRING_SERVICE_H
24#define MYSQL_STRING_SERVICE_H
25
27
29
30#include "my_inttypes.h"
31
32/* clang-format off */
33/**
34 @defgroup group_string_component_services_inventory MySQL string services
35 @ingroup group_components_services_inventory
36*/
37
38/* clang-format on */
39
41
42/**
43 Get the "utf8mb4" CHARSET_INFO.
44*/
46
47/**
48 Find a CHARSET_INFO by name.
49 @param name The character set name, expressed in ASCII, zero terminated.
50*/
52
53/**
54 @ingroup group_string_component_services_inventory
55
56 Lookup available character sets.
57 Status: Active.
58*/
60/** @sa get_charset_utf8mb4_v1_t */
62/** @sa get_charset_by_name_v1_t */
65
66/**
67 The string functions as a service to the mysql_server component.
68 So, that by default this service is available to all the components
69 register to the server.
70*/
71
74
75/**
76 @ingroup group_string_component_services_inventory
77
78 Service for String create and destroy.
79*/
80BEGIN_SERVICE_DEFINITION(mysql_string_factory)
81/**
82 Creates a new instance of string object
83
84 @param out_string holds pointer to newly created string object.
85 @return Status of performed operation
86 @retval false success @retval true failure
87*/
89
90/**
91 Destroys specified string object and data contained by it.
92
93 @param string String object handle to release.
94 @return Status of performed operation
95 @retval false success
96 @retval true failure
97*/
99END_SERVICE_DEFINITION(mysql_string_factory)
100
101/**
102 @ingroup group_string_component_services_inventory
103
104 Service for String case conversions, to lower case and to upper case.
105*/
106BEGIN_SERVICE_DEFINITION(mysql_string_case)
107/**
108 Convert a String pointed by handle to lower case. Conversion depends on the
109 client character set info
110
111 @param out_string Holds the converted lower case string object.
112 @param in_string Pointer to string object to be converted.
113 @return Status of performed operation
114 @retval false success
115 @retval true failure
116*/
118
119/**
120 Convert a String pointed by handle to upper case. Conversion depends on the
121 client character set info
122
123 @param out_string Holds the converted upper case string object.
124 @param in_string Pointer to string object to be converted.
125 @return Status of performed operation
126 @retval false success
127 @retval true failure
128*/
130END_SERVICE_DEFINITION(mysql_string_case)
131
132/**
133 @ingroup group_string_component_services_inventory
134
135 Service for conversions, string to buffer and buffer to string.
136 Status: Deprecated, use mysql_string_charset_converter instead.
137*/
138BEGIN_SERVICE_DEFINITION(mysql_string_converter)
139/**
140 allocates a string object and converts the character buffer to string
141 of specified charset_name.
142 please call destroy() api to free the allocated string after this api.
143
144 @param [out] out_string Pointer to string object handle to set new string
145 to.
146 @param in_buffer Pointer to the buffer with data to be interpreted as
147 string.
148 @param length Length of the buffer to copy into string, in bytes, not in
149 character count.
150 @param charset_name charset that is used for conversion.
151 @return Status of performed operation
152 @retval false success
153 @retval true failure
154*/
155DECLARE_BOOL_METHOD(convert_from_buffer,
156 (my_h_string * out_string, const char *in_buffer,
157 uint64 length, const char *charset_name));
158
159/**
160 converts the mysql_string to the character set specified by
161 charset_name parameter.
162
163 @param in_string Pointer to string object handle to set new string
164 to.
165 @param [out] out_buffer Pointer to the buffer with data to be interpreted
166 as characters.
167 @param length Length of the buffer to hold out put in characters.
168 @param charset_name Handle to charset that is used for conversion.
169 @return Status of performed operation
170 @retval false success
171 @retval true failure
172*/
173DECLARE_BOOL_METHOD(convert_to_buffer,
174 (my_h_string in_string, char *out_buffer, uint64 length,
175 const char *charset_name));
176END_SERVICE_DEFINITION(mysql_string_converter)
177
178/**
179 Converts a character buffer to string of specified charset
180 to a string object.
181 The caller provides the destination string object,
182 which content will be modified.
183
184 @param [in,out] dest_string Destination string.
185 @param src_buffer Source buffer
186 @param src_length Length of the source buffer, in bytes
187 @param src_charset CHARSET is the source buffer
188 @return Conversion status
189 @retval false success
190 @retval true failure
191*/
193 my_h_string dest_string, const char *src_buffer, uint64 src_length,
194 CHARSET_INFO_h src_charset);
195
196/**
197 Converts the mysql_string to a given character set.
198
199 @param src_string Source string to convert
200 @param [out] dest_buffer Destination buffer
201 @param dest_length Length, in charset characters, of the destination buffer
202 @param dest_charset Destination CHARSET, that is, character set to convert to
203 @return Conversion status
204 @retval false success
205 @retval true failure
206*/
208 my_h_string src_string, char *dest_buffer, uint64 dest_length,
209 CHARSET_INFO_h dest_charset);
210
211/**
212 @ingroup group_string_component_services_inventory
213
214 Service for conversions, string to buffer and buffer to string.
215 Status: Active.
216*/
217BEGIN_SERVICE_DEFINITION(mysql_string_charset_converter)
218/** @sa convert_from_buffer_v2_t */
219convert_from_buffer_v2_t convert_from_buffer;
220/** @sa convert_to_buffer_v2_t */
221convert_to_buffer_v2_t convert_to_buffer;
222END_SERVICE_DEFINITION(mysql_string_charset_converter)
223
224/**
225 @ingroup group_string_component_services_inventory
226
227 Service to get a character in String and number of characters in string
228*/
229BEGIN_SERVICE_DEFINITION(mysql_string_character_access)
230/**
231 Gets client character code of character on specified index position in
232 string to a specified buffer.
233
234 @param string String object handle to get character from.
235 @param index Index, position of character to query.
236 @param [out] out_char Pointer to long value to store character to.
237 @return Status of performed operation
238 @retval false success
239 @retval true failure
240*/
241DECLARE_BOOL_METHOD(get_char,
242 (my_h_string string, uint index, ulong *out_char));
243
244/**
245 Gets length of specified string expressed as number of characters.
246
247 @param string String object handle to get length of.
248 @param [out] out_length Pointer to 64bit value to store length of string to.
249 @return Status of performed operation
250 @retval false success
251 @retval true failure
252*/
253DECLARE_BOOL_METHOD(get_char_length, (my_h_string string, uint *out_length));
254END_SERVICE_DEFINITION(mysql_string_character_access)
255
256/**
257 @ingroup group_string_component_services_inventory
258
259 Service to get a byte in String and number of bytes in string
260*/
261BEGIN_SERVICE_DEFINITION(mysql_string_byte_access)
262/**
263 Gets byte code of string at specified index position to a
264 specified 32-bit buffer.
265
266 @param string String object handle to get character from.
267 @param index Index, position of character to query.
268 @param [out] out_char Pointer to 32bit value to store byte to.
269 @return Status of performed operation
270 @retval false success
271 @retval true failure
272*/
273DECLARE_BOOL_METHOD(get_byte, (my_h_string string, uint index, uint *out_char));
274
275/**
276 Gets length of specified string expressed as number of bytes.
277
278 @param string String object handle to get length of.
279 @param [out] out_length Pointer to 32bit value to store length of string to.
280 @return Status of performed operation
281 @retval false success
282 @retval true failure
283*/
284DECLARE_BOOL_METHOD(get_byte_length, (my_h_string string, uint *out_length));
285END_SERVICE_DEFINITION(mysql_string_byte_access)
286
287/**
288 @ingroup group_string_component_services_inventory
289
290 Service for listing Strings by iterator.
291*/
292BEGIN_SERVICE_DEFINITION(mysql_string_iterator)
293/**
294 Creates an iterator for a specified string to allow iteration through all
295 characters in the string.
296
297 @param string String object handle to get iterator to.
298 @param [out] out_iterator Pointer to string iterator handle to store result
299 object to.
300 @return Status of performed operation
301 @retval false success
302 @retval true failure
303*/
304DECLARE_BOOL_METHOD(iterator_create,
305 (my_h_string string, my_h_string_iterator *out_iterator));
306
307/**
308 Retrieves character type code at current iterator position and advances the
309 iterator. Character type code is a bit mask describing various properties.
310 Refer to types in mysql_string_bits.h
311
312 @param iter String iterator object handle to advance.
313 @param [out] out_ctype Pointer to 64bit value to store character type.
314 May be NULL to omit retrieval and just advance
315 the iterator.
316 @return Status of performed operation
317 @retval false success
318 @retval true failure
319*/
320DECLARE_BOOL_METHOD(iterator_get_next,
321 (my_h_string_iterator iter, int *out_ctype));
322
323/**
324 Releases the string iterator object specified.
325
326 @param iter String iterator object to handle the release.
327 @return Status of performed operation
328 @retval false success
329 @retval true failure
330*/
331DECLARE_METHOD(void, iterator_destroy, (my_h_string_iterator iter));
332END_SERVICE_DEFINITION(mysql_string_iterator)
333
334/**
335 @ingroup group_string_component_services_inventory
336
337 Service for String c_type.
338*/
339BEGIN_SERVICE_DEFINITION(mysql_string_ctype)
340/**
341 Checks if character on current position the iterator points to is an upper
342 case.
343
344 @param iter String iterator object handle to advance.
345 @param [out] out Pointer to bool value to store if character is an upper
346 case.
347 @return Status of performed operation
348 @retval false success
349 @retval true failure
350*/
351DECLARE_BOOL_METHOD(is_upper, (my_h_string_iterator iter, bool *out));
352
353/**
354 Checks if character on current position the iterator points to is a lower
355 case.
356
357 @param iter String iterator object handle to advance.
358 @param [out] out Pointer to bool value to store if character is a lower
359 case.
360 @return Status of performed operation
361 @retval false success
362 @retval true failure
363*/
364DECLARE_BOOL_METHOD(is_lower, (my_h_string_iterator iter, bool *out));
365
366/**
367 Checks if character on current position the iterator points to is a digit.
368
369 @param iter String iterator object handle to advance.
370 @param [out] out Pointer to bool value to store if character is a digit.
371 @return Status of performed operation
372 @retval false success
373 @retval true failure
374*/
376END_SERVICE_DEFINITION(mysql_string_ctype)
377
378/**
379 @ingroup group_string_component_services_inventory
380
381 Service for retrieving one character from a string.
382 It relies on string iterator and access ulong representation
383 of the character.
384*/
385BEGIN_SERVICE_DEFINITION(mysql_string_value)
386
387/**
388 Retrieves character value at current iterator position
389
390 @param iter String iterator object handle
391 @param [out] out Pointer to long value to store character to
392
393 @return Status of performed operation
394 @retval false success
395 @retval true failure
396*/
398
399END_SERVICE_DEFINITION(mysql_string_value)
400
401/* mysql_string_manipulation_v1 service. */
402
403/**
404 Reset a string to the empty string.
405
406 @param [in, out] s The string to reset.
407*/
409
410/**
411 @ingroup group_string_component_services_inventory
412
413 Reset a string to the empty string.
414*/
415BEGIN_SERVICE_DEFINITION(mysql_string_reset)
417END_SERVICE_DEFINITION(mysql_string_reset)
418
419/**
420 Substring.
421 Allocates a string object and sets it value as substring of the input
422 string. Caller must free the allocated string by calling destroy().
423
424 @param [in] in_string String handle to extract substring from.
425 @param [in] offset Character offset of the substring.
426 @param [in] count Number of characters of the substring.
427 @param [out] out_string Pointer to string handle holding the created result
428string.
429 @return Status of performed operation
430 @retval false success
431 @retval true failure
432*/
434 my_h_string in_string, uint offset, uint count, my_h_string *out_string);
435
436/**
437 @ingroup group_string_component_services_inventory
438
439 Substring a string.
440*/
441BEGIN_SERVICE_DEFINITION(mysql_string_substr)
443END_SERVICE_DEFINITION(mysql_string_substr)
444
445/**
446 Append a string.
447
448 @param [in, out] s1 The string to append to.
449 @param [in] s2 The string to append.
450*/
452 my_h_string s2);
453
454/**
455 @ingroup group_string_component_services_inventory
456
457 Append a string to another one.
458*/
459BEGIN_SERVICE_DEFINITION(mysql_string_append)
461END_SERVICE_DEFINITION(mysql_string_append)
462
463/**
464 Compare two strings.
465
466 @param [in] s1 First string to compare.
467 @param [in] s2 Second string to compare.
468 @param [out] cmp Comparison result (negative, zero, or positive) .
469*/
471 my_h_string s2,
472 int *cmp);
473
474/**
475 @ingroup group_string_component_services_inventory
476
477 Compare two strings.
478*/
479BEGIN_SERVICE_DEFINITION(mysql_string_compare)
481END_SERVICE_DEFINITION(mysql_string_compare)
482
483/**
484 Access the string raw data.
485 The raw data returned is usable only while the string object
486 is valid.
487
488 @param [in] s String
489 @param [out] buffer_pointer String raw buffer.
490 @param [out] buffer_length String raw buffer size.
491 @param [out] buffer_charset String character set.
492*/
494 my_h_string s, const char **buffer_pointer, size_t *buffer_length,
495 CHARSET_INFO_h *buffer_charset);
496
497/**
498 @ingroup group_string_component_services_inventory
499
500 Access the string raw data.
501*/
502BEGIN_SERVICE_DEFINITION(mysql_string_get_data_in_charset)
504END_SERVICE_DEFINITION(mysql_string_get_data_in_charset)
505
506#endif /* MYSQL_STRING_SERVICE_H */
int get_byte(azio_stream *s)
Definition: azio.cc:225
int destroy(azio_stream *s)
Definition: azio.cc:371
Definition: item_cmpfunc.h:1662
static int cmp(Bigint *a, Bigint *b)
Definition: dtoa.cc:1059
static bool is_digit(unsigned codepoint)
Return true if the codepoint is a Unicode digit.
Definition: json_path.cc:685
Some integer typedefs for easier portability.
uint64_t uint64
Definition: my_inttypes.h:68
static int count
Definition: myisam_ftdump.cc:44
mysql_service_status_t(* mysql_string_get_data_v1_t)(my_h_string s, const char **buffer_pointer, size_t *buffer_length, CHARSET_INFO_h *buffer_charset)
Access the string raw data.
Definition: mysql_string.h:493
mysql_service_status_t(* convert_from_buffer_v2_t)(my_h_string dest_string, const char *src_buffer, uint64 src_length, CHARSET_INFO_h src_charset)
Converts a character buffer to string of specified charset to a string object.
Definition: mysql_string.h:192
CHARSET_INFO_h(* get_charset_utf8mb4_v1_t)()
Get the "utf8mb4" CHARSET_INFO.
Definition: mysql_string.h:45
CHARSET_INFO_h(* get_charset_by_name_v1_t)(const char *name)
Find a CHARSET_INFO by name.
Definition: mysql_string.h:51
mysql_service_status_t(* mysql_string_reset_v1_t)(my_h_string s)
Reset a string to the empty string.
Definition: mysql_string.h:408
struct CHARSET_INFO_h_imp * CHARSET_INFO_h
Definition: mysql_string.h:40
mysql_service_status_t(* convert_to_buffer_v2_t)(my_h_string src_string, char *dest_buffer, uint64 dest_length, CHARSET_INFO_h dest_charset)
Converts the mysql_string to a given character set.
Definition: mysql_string.h:207
mysql_service_status_t(* mysql_string_substr_v1_t)(my_h_string in_string, uint offset, uint count, my_h_string *out_string)
Substring.
Definition: mysql_string.h:433
mysql_service_status_t(* mysql_string_compare_v1_t)(my_h_string s1, my_h_string s2, int *cmp)
Compare two strings.
Definition: mysql_string.h:470
mysql_service_status_t(* mysql_string_append_v1_t)(my_h_string s1, my_h_string s2)
Append a string.
Definition: mysql_string.h:451
Type information related to strings.
std::string HARNESS_EXPORT reset()
get 'reset attributes' ESC sequence.
Definition: vt100.cc:36
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
char tolower(const char &ch)
Definition: parsing_helpers.h:40
void get(PSI_field *, PSI_longlong *) noexcept
Definition: pfs_plugin_column_bigint_v1_all_empty.cc:31
static mysql_service_status_t create(const char *service_names[], reference_caching_channel *out_channel) noexcept
Definition: component.cc:44
static int compare(size_t a, size_t b)
Function to compare two size_t integers for their relative order.
Definition: rpl_utility.cc:106
#define DECLARE_METHOD(retval, name, args)
Declares a method as a part of the Service definition.
Definition: service.h:102
int mysql_service_status_t
Specific type for the service status return values.
Definition: service.h:33
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:90
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:85
#define DEFINE_SERVICE_HANDLE(name)
Defines an object type that is meant for carrying handles to the implementation-specific objects used...
Definition: service.h:128
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:111
case opt name
Definition: sslopt-case.h:32
Definition: mysql_string_service.cc:59
Definition: mysql_string_service.cc:61