85 {
86 if (!str) {
87 if (endptr) {
88 *endptr = const_cast<char*>(str);
89 }
90 return 0;
91 }
92
93 const char* p = str;
95 bool negative = false;
96
97
98 while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || *p == '\f' || *p == '\v') {
99 p++;
100 }
101
102
103 if (*p == '-') {
104 negative = true;
105 p++;
106 } else if (*p == '+') {
107 p++;
108 }
109
110
111 if (base == 0) {
112 if (*p == '0') {
113 if (*(p + 1) == 'x' || *(p + 1) == 'X') {
114 base = 16;
115 p += 2;
116 } else {
117 base = 8;
118 p++;
119 }
120 } else {
121 base = 10;
122 }
123 } else if (base == 16) {
124
125 if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) {
126 p += 2;
127 }
128 }
129
130
131 if (base < 2 || base > 36) {
132 if (endptr) {
133 *endptr = const_cast<char*>(str);
134 }
135 return 0;
136 }
137
138
139 const char* start = p;
142 p++;
143 }
144
145
146 if (endptr) {
147 if (p == start) {
148
149 *endptr = const_cast<char*>(str);
150 } else {
151 *endptr = const_cast<char*>(p);
152 }
153 }
154
156}
static int charToDigit(char c)
static bool isDigitInBase(char c, int base)
expected< T, E > result
Alias for expected (Rust-style naming)