string.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_GPR_STRING_H
20 #define GRPC_CORE_LIB_GPR_STRING_H
21 
23 
24 #include <stdbool.h>
25 #include <stddef.h>
26 
27 #include <string>
28 
30 
31 /* String utility functions */
32 
33 /* Flags for gpr_dump function. */
34 #define GPR_DUMP_HEX 0x00000001
35 #define GPR_DUMP_ASCII 0x00000002
36 
37 /* Converts array buf, of length len, into a C string according to the flags.
38  Result should be freed with gpr_free() */
39 char* gpr_dump(const char* buf, size_t len, uint32_t flags);
40 /* Converts array buf, of length len, into a C string according to the flags.
41  The length of the returned buffer is stored in out_len.
42  Result should be freed with gpr_free() */
43 char* gpr_dump_return_len(const char* buf, size_t len, uint32_t flags,
44  size_t* out_len);
45 
46 /* Parses an array of bytes into an integer (base 10). Returns 1 on success,
47  0 on failure. */
48 int gpr_parse_bytes_to_uint32(const char* buf, size_t len, uint32_t* result);
49 
50 /* Minimum buffer size for calling ltoa */
51 #define GPR_LTOA_MIN_BUFSIZE (3 * sizeof(long))
52 
53 /* Convert a long to a string in base 10; returns the length of the
54  output string (or 0 on failure).
55  output must be at least GPR_LTOA_MIN_BUFSIZE bytes long. */
56 int gpr_ltoa(long value, char* output);
57 
58 /* Minimum buffer size for calling int64toa */
59 #define GPR_INT64TOA_MIN_BUFSIZE (3 * sizeof(int64_t))
60 
61 /* Convert an int64 to a string in base 10; returns the length of the
62 output string (or 0 on failure).
63 output must be at least GPR_INT64TOA_MIN_BUFSIZE bytes long.
64 NOTE: This function ensures sufficient bit width even on Win x64,
65 where long is 32bit is size.*/
66 int int64_ttoa(int64_t value, char* output);
67 
68 // Parses a non-negative number from a value string. Returns -1 on error.
69 int gpr_parse_nonnegative_int(const char* value);
70 
71 /* Reverse a run of bytes */
72 void gpr_reverse_bytes(char* str, int len);
73 
74 /* Pad a string with flag characters. The given length specifies the minimum
75  field width. The input string is never truncated. */
76 char* gpr_leftpad(const char* str, char flag, size_t length);
77 
78 /* Join a set of strings, returning the resulting string.
79  Total combined length (excluding null terminator) is returned in final_length
80  if it is non-null. */
81 char* gpr_strjoin(const char** strs, size_t nstrs, size_t* final_length);
82 
83 /* Join a set of strings using a separator, returning the resulting string.
84  Total combined length (excluding null terminator) is returned in final_length
85  if it is non-null. */
86 char* gpr_strjoin_sep(const char** strs, size_t nstrs, const char* sep,
87  size_t* final_length);
88 
89 void gpr_string_split(const char* input, const char* sep, char*** strs,
90  size_t* nstrs);
91 
92 /* Returns a string that represents tm according to RFC-3339, and,
93  more specifically, follows:
94  https://developers.google.com/protocol-buffers/docs/proto3#json
95 
96  Uses RFC 3339, where generated output will always be Z-normalized and uses
97  0, 3, 6 or 9 fractional digits. */
99 
102 int gpr_stricmp(const char* a, const char* b);
103 int gpr_strincmp(const char* a, const char* b, size_t n);
104 
105 void* gpr_memrchr(const void* s, int c, size_t n);
106 
107 /* Try to parse given string into a boolean value.
108  When parsed successfully, dst will have the value and returns true.
109  Otherwise, it returns false. */
110 bool gpr_parse_bool_value(const char* value, bool* dst);
111 
112 #endif /* GRPC_CORE_LIB_GPR_STRING_H */
xds_interop_client.str
str
Definition: xds_interop_client.py:487
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
flag
uint32_t flag
Definition: ssl_versions.cc:162
dst
static const char dst[]
Definition: test-fs-copyfile.c:37
gpr_strjoin_sep
char * gpr_strjoin_sep(const char **strs, size_t nstrs, const char *sep, size_t *final_length)
Definition: string.cc:239
gpr_leftpad
char * gpr_leftpad(const char *str, char flag, size_t length)
Definition: string.cc:225
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
gpr_strincmp
int gpr_strincmp(const char *a, const char *b, size_t n)
Definition: string.cc:270
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
gpr_parse_nonnegative_int
int gpr_parse_nonnegative_int(const char *value)
Definition: string.cc:218
gpr_memrchr
void * gpr_memrchr(const void *s, int c, size_t n)
Definition: string.cc:313
gpr_parse_bytes_to_uint32
int gpr_parse_bytes_to_uint32(const char *buf, size_t len, uint32_t *result)
Definition: string.cc:149
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
int64_ttoa
int int64_ttoa(int64_t value, char *output)
Definition: string.cc:197
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
text_format_test_wrapper.sep
sep
Definition: text_format_test_wrapper.py:34
gpr_stricmp
int gpr_stricmp(const char *a, const char *b)
Definition: string.cc:282
gpr_format_timespec
std::string gpr_format_timespec(gpr_timespec)
Definition: string.cc:55
gpr_dump_return_len
char * gpr_dump_return_len(const char *buf, size_t len, uint32_t flags, size_t *out_len)
Definition: string.cc:130
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
gpr_ltoa
int gpr_ltoa(long value, char *output)
Definition: string.cc:176
gpr_types.h
value
const char * value
Definition: hpack_parser_table.cc:165
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
gpr_reverse_bytes
void gpr_reverse_bytes(char *str, int len)
Definition: string.cc:167
gpr_strjoin
char * gpr_strjoin(const char **strs, size_t nstrs, size_t *final_length)
Definition: string.cc:235
gpr_dump
char * gpr_dump(const char *buf, size_t len, uint32_t flags)
Definition: string.cc:144
input
std::string input
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/tokenizer_unittest.cc:197
gpr_parse_bool_value
bool gpr_parse_bool_value(const char *value, bool *dst)
Definition: string.cc:325
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
gpr_timespec
Definition: gpr_types.h:50
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
gpr_string_split
void gpr_string_split(const char *input, const char *sep, char ***strs, size_t *nstrs)
Definition: string.cc:300
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:25