Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/string/byte"

From cppreference.com
< cpp‎ | string
(improve explanation)
m (First statement: add note that in NTBS a byte sequence before terminator might be empty.)
 
(23 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{title|Narrow null-terminated strings}}
+
{{title|Null-terminated byte strings}}
{{cpp/string/narrow/sidebar}}
+
{{cpp/string/byte/navbar}}
  
A null-terminated character string, or NTBS, is a character sequence, that consists of nonzero elements, except the last element (the terminating null-character), which has the value zero.
+
A null-terminated byte string (NTBS) is a possibly empty sequence of nonzero bytes followed by a byte with value zero (the terminating null character). Each byte in a byte string encodes one character of some character set. For example, the character array {{c|{'\x63', '\x61', '\x74', '\0'}<!---->}} is an NTBS holding the string {{c|"cat"}} in ASCII encoding.
  
A null-terminated multibyte character string, or NTMBS, is a null-terminated character string, that consists of valid multibyte characters. The string must begin and end with the shift state. A multibyte character string is compatible with regular character strings, that is, can be processed using the same facilities, except for the length calculation.
+
===Functions===
 +
{{dsc begin}}
 +
{{dsc h2|Character classification}}
 +
{{dsc header|cctype}}
 +
{{dsc inc|cpp/string/byte/dsc isalnum}}
 +
{{dsc inc|cpp/string/byte/dsc isalpha}}
 +
{{dsc inc|cpp/string/byte/dsc islower}}
 +
{{dsc inc|cpp/string/byte/dsc isupper}}
 +
{{dsc inc|cpp/string/byte/dsc isdigit}}
 +
{{dsc inc|cpp/string/byte/dsc isxdigit}}
 +
{{dsc inc|cpp/string/byte/dsc iscntrl}}
 +
{{dsc inc|cpp/string/byte/dsc isgraph}}
 +
{{dsc inc|cpp/string/byte/dsc isspace}}
 +
{{dsc inc|cpp/string/byte/dsc isblank}}
 +
{{dsc inc|cpp/string/byte/dsc isprint}}
 +
{{dsc inc|cpp/string/byte/dsc ispunct}}
  
{{todo|explain shift state}}
+
{{dsc h2|Character manipulation}}
 +
{{dsc inc|cpp/string/byte/dsc tolower}}
 +
{{dsc inc|cpp/string/byte/dsc toupper}}
 +
{{dsc end}}
 +
{{cpp/string/character classes}}
 +
{{dsc begin}}
  
{{dcl list begin}}
+
{{dsc h2|Conversions to numeric formats}}
{{dcl list h1 | Functions}}
+
{{dsc header|cstdlib}}
 +
{{dsc inc|cpp/string/byte/dsc atof}}
 +
{{dsc inc|cpp/string/byte/dsc atoi}}
 +
{{dsc inc|cpp/string/byte/dsc strtol}}
 +
{{dsc inc|cpp/string/byte/dsc strtoul}}
 +
{{dsc inc|cpp/string/byte/dsc strtof}}
 +
{{dsc header|cinttypes}}
 +
{{dsc inc|cpp/string/byte/dsc strtoimax}}
  
{{dcl list h2 | Character manipulation}}
+
{{dsc h2|String manipulation}}
{{dcl list template | cpp/string/narrow/dcl list isalnum}}
+
{{dsc header|cstring}}
{{dcl list template | cpp/string/narrow/dcl list isalpha}}
+
{{dsc inc|cpp/string/byte/dsc strcpy}}
{{dcl list template | cpp/string/narrow/dcl list islower}}
+
{{dsc inc|cpp/string/byte/dsc strncpy}}
{{dcl list template | cpp/string/narrow/dcl list isupper}}
+
{{dsc inc|cpp/string/byte/dsc strcat}}
{{dcl list template | cpp/string/narrow/dcl list isdigit}}
+
{{dsc inc|cpp/string/byte/dsc strncat}}
{{dcl list template | cpp/string/narrow/dcl list isxdigit}}
+
{{dsc inc|cpp/string/byte/dsc strxfrm}}
{{dcl list template | cpp/string/narrow/dcl list iscntrl}}
+
{{dcl list template | cpp/string/narrow/dcl list isgraph}}
+
{{dcl list template | cpp/string/narrow/dcl list isspace}}
+
{{dcl list template | cpp/string/narrow/dcl list isprint}}
+
{{dcl list template | cpp/string/narrow/dcl list ispunct}}
+
{{dcl list template | cpp/string/narrow/dcl list tolower}}
+
{{dcl list template | cpp/string/narrow/dcl list toupper}}
+
{{dcl list end}}
+
{{cpp/string/character classes}}
+
{{dcl list begin}}
+
  
{{dcl list h2 | Conversions to numeric formats}}
+
{{dsc h2|String examination}}
{{dcl list template | cpp/string/narrow/dcl list atof}}
+
{{dsc header|cstring}}
{{dcl list template | cpp/string/narrow/dcl list atoi}}
+
{{dsc inc|cpp/string/byte/dsc strlen}}
{{dcl list template | cpp/string/narrow/dcl list strtol}}
+
{{dsc inc|cpp/string/byte/dsc strcmp}}
{{dcl list template | cpp/string/narrow/dcl list strtoul}}
+
{{dsc inc|cpp/string/byte/dsc strncmp}}
{{dcl list template | cpp/string/narrow/dcl list strtof}}
+
{{dsc inc|cpp/string/byte/dsc strcoll}}
 +
{{dsc inc|cpp/string/byte/dsc strchr}}
 +
{{dsc inc|cpp/string/byte/dsc strrchr}}
 +
{{dsc inc|cpp/string/byte/dsc strspn}}
 +
{{dsc inc|cpp/string/byte/dsc strcspn}}
 +
{{dsc inc|cpp/string/byte/dsc strpbrk}}
 +
{{dsc inc|cpp/string/byte/dsc strstr}}
 +
{{dsc inc|cpp/string/byte/dsc strtok}}
  
{{dcl list h2 | String manipulation}}
+
{{dsc h2|Character array functions}}
{{dcl list template | cpp/string/narrow/dcl list strcpy}}
+
{{dsc header|cstring}}
{{dcl list template | cpp/string/narrow/dcl list strncpy}}
+
{{dsc inc|cpp/string/byte/dsc memchr}}
{{dcl list template | cpp/string/narrow/dcl list strcat}}
+
{{dsc inc|cpp/string/byte/dsc memcmp}}
{{dcl list template | cpp/string/narrow/dcl list strncat}}
+
{{dsc inc|cpp/string/byte/dsc memset}}
{{dcl list template | cpp/string/narrow/dcl list strxfrm}}
+
{{dsc inc|cpp/string/byte/dsc memcpy}}
 +
{{dsc inc|cpp/string/byte/dsc memmove}}
  
{{dcl list h2 | String examination}}
+
{{dsc h2|Miscellaneous}}
{{dcl list template | cpp/string/narrow/dcl list strlen}}
+
{{dsc header|cstring}}
{{dcl list template | cpp/string/narrow/dcl list strcmp}}
+
{{dsc inc|cpp/string/byte/dsc strerror}}
{{dcl list template | cpp/string/narrow/dcl list strncmp}}
+
{{dsc end}}
{{dcl list template | cpp/string/narrow/dcl list strcoll}}
+
{{dcl list template | cpp/string/narrow/dcl list strchr}}
+
{{dcl list template | cpp/string/narrow/dcl list strrchr}}
+
{{dcl list template | cpp/string/narrow/dcl list strspn}}
+
{{dcl list template | cpp/string/narrow/dcl list strcspn}}
+
{{dcl list template | cpp/string/narrow/dcl list strpbrk}}
+
{{dcl list template | cpp/string/narrow/dcl list strstr}}
+
{{dcl list template | cpp/string/narrow/dcl list strtok}}
+
  
{{dcl list h2 | Memory manipulation}}
+
===See also===
{{dcl list template | cpp/string/narrow/dcl list memchr}}
+
{{dsc begin}}
{{dcl list template | cpp/string/narrow/dcl list memcmp}}
+
{{dsc see c|c/string/byte|{{tt|Null}}-terminated byte strings|nomono=true}}
{{dcl list template | cpp/string/narrow/dcl list memset}}
+
{{dsc end}}
{{dcl list template | cpp/string/narrow/dcl list memcpy}}
+
{{dcl list template | cpp/string/narrow/dcl list memmove}}
+
  
{{dcl list h2 | Miscellaneous}}
+
{{langlinks|cs|de|es|fr|it|ja|pl|pt|ru|zh}}
{{dcl list template | cpp/string/narrow/dcl list strerror}}
+
{{dcl list end}}
+

Latest revision as of 14:28, 21 February 2023

A null-terminated byte string (NTBS) is a possibly empty sequence of nonzero bytes followed by a byte with value zero (the terminating null character). Each byte in a byte string encodes one character of some character set. For example, the character array {'\x63', '\x61', '\x74', '\0'} is an NTBS holding the string "cat" in ASCII encoding.

Contents

[edit] Functions

Character classification
Defined in header <cctype>
checks if a character is alphanumeric
(function) [edit]
checks if a character is alphabetic
(function) [edit]
checks if a character is lowercase
(function) [edit]
checks if a character is an uppercase character
(function) [edit]
checks if a character is a digit
(function) [edit]
checks if a character is a hexadecimal character
(function) [edit]
checks if a character is a control character
(function) [edit]
checks if a character is a graphical character
(function) [edit]
checks if a character is a space character
(function) [edit]
(C++11)
checks if a character is a blank character
(function) [edit]
checks if a character is a printing character
(function) [edit]
checks if a character is a punctuation character
(function) [edit]
Character manipulation
converts a character to lowercase
(function) [edit]
converts a character to uppercase
(function) [edit]
ASCII values characters

iscntrl
iswcntrl

isprint
iswprint

isspace
iswspace

isblank
iswblank

isgraph
iswgraph

ispunct
iswpunct

isalnum
iswalnum

isalpha
iswalpha

isupper
iswupper

islower
iswlower

isdigit
iswdigit

isxdigit
iswxdigit

decimal hexadecimal octal
0–8 \x0\x8 \0\10 control codes (NUL, etc.) ≠0 0 0 0 0 0 0 0 0 0 0 0
9 \x9 \11 tab (\t) ≠0 0 ≠0 ≠0 0 0 0 0 0 0 0 0
10–13 \xA\xD \12\15 whitespaces (\n, \v, \f, \r) ≠0 0 ≠0 0 0 0 0 0 0 0 0 0
14–31 \xE\x1F \16\37 control codes ≠0 0 0 0 0 0 0 0 0 0 0 0
32 \x20 \40 space 0 ≠0 ≠0 ≠0 0 0 0 0 0 0 0 0
33–47 \x21\x2F \41\57 !"#$%&'()*+,-./ 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
48–57 \x30\x39 \60\71 0123456789 0 ≠0 0 0 ≠0 0 ≠0 0 0 0 ≠0 ≠0
58–64 \x3A\x40 \72\100 :;<=>?@ 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
65–70 \x41\x46 \101\106 ABCDEF 0 ≠0 0 0 ≠0 0 ≠0 ≠0 ≠0 0 0 ≠0
71–90 \x47\x5A \107\132 GHIJKLMNOP
QRSTUVWXYZ
0 ≠0 0 0 ≠0 0 ≠0 ≠0 ≠0 0 0 0
91–96 \x5B\x60 \133\140 [\]^_` 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
97–102 \x61\x66 \141\146 abcdef 0 ≠0 0 0 ≠0 0 ≠0 ≠0 0 ≠0 0 ≠0
103–122 \x67\x7A \147\172 ghijklmnop
qrstuvwxyz
0 ≠0 0 0 ≠0 0 ≠0 ≠0 0 ≠0 0 0
123–126 \x7B\x7E \172\176 {|}~ 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
127 \x7F \177 backspace character (DEL) ≠0 0 0 0 0 0 0 0 0 0 0 0
Conversions to numeric formats
Defined in header <cstdlib>
converts a byte string to a floating point value
(function) [edit]
converts a byte string to an integer value
(function) [edit]
converts a byte string to an integer value
(function) [edit]
converts a byte string to an unsigned integer value
(function) [edit]
converts a byte string to a floating-point value
(function) [edit]
Defined in header <cinttypes>
(C++11)(C++11)
converts a byte string to std::intmax_t or std::uintmax_t
(function) [edit]
String manipulation
Defined in header <cstring>
copies one string to another
(function) [edit]
copies a certain amount of characters from one string to another
(function) [edit]
concatenates two strings
(function) [edit]
concatenates a certain amount of characters of two strings
(function) [edit]
transform a string so that strcmp would produce the same result as strcoll
(function) [edit]
String examination
Defined in header <cstring>
returns the length of a given string
(function) [edit]
compares two strings
(function) [edit]
compares a certain number of characters from two strings
(function) [edit]
compares two strings in accordance to the current locale
(function) [edit]
finds the first occurrence of a character
(function) [edit]
finds the last occurrence of a character
(function) [edit]
returns the length of the maximum initial segment that consists
of only the characters found in another byte string
(function) [edit]
returns the length of the maximum initial segment that consists
of only the characters not found in another byte string
(function) [edit]
finds the first location of any character from a set of separators
(function) [edit]
finds the first occurrence of a substring of characters
(function) [edit]
finds the next token in a byte string
(function) [edit]
Character array functions
Defined in header <cstring>
searches an array for the first occurrence of a character
(function) [edit]
compares two buffers
(function) [edit]
fills a buffer with a character
(function) [edit]
copies one buffer to another
(function) [edit]
moves one buffer to another
(function) [edit]
Miscellaneous
Defined in header <cstring>
returns a text version of a given error code
(function) [edit]

[edit] See also

C documentation for Null-terminated byte strings