1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
|
<html>
<head>
<title>~/src/firstworks/rudiments-0.31/include/rudiments/charstring.h.html</title>
<meta name="Generator" content="Vim/7.0">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#0000ff">// Copyright (c) 2003 David Muse</font>
<font color="#0000ff">// See the COPYING file for more information.</font>
<font color="#a020f0">#ifndef RUDIMENTS_CHARSTRING_H</font>
<font color="#a020f0">#define RUDIMENTS_CHARSTRING_H</font>
<font color="#a020f0">#include </font><font color="#ff00ff"><rudiments/private/charstringincludes.h></font>
<font color="#0000ff">// The charstring class provides methods for manipulating strings.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Unlike the functions in string.h, these methods are NULL safe. If any of</font>
<font color="#0000ff">// the pointer arguments are NULL, your application will not crash.</font>
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
<font color="#2e8b57"><b>namespace</b></font> rudiments {
<font color="#a020f0">#endif</font>
<font color="#2e8b57"><b>class</b></font> charstring {
<font color="#a52a2a"><b>public</b></font>:
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>size_t</b></font> length(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string);
<font color="#0000ff">// Returns the length of "string".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>size_t</b></font> length(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *string);
<font color="#0000ff">// Returns the length of "string".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> zero(<font color="#2e8b57"><b>char</b></font> *str, <font color="#2e8b57"><b>size_t</b></font> size);
<font color="#0000ff">// Sets "size" bytes of "str" to NULL.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *append(<font color="#2e8b57"><b>char</b></font> *dest, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *source);
<font color="#0000ff">// Appends "source" to "dest". Assumes that there</font>
<font color="#0000ff">// is enough room remaining in "dest" to accommodate</font>
<font color="#0000ff">// the new string.</font>
<font color="#0000ff">// Returns a pointer to "dest".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *append(<font color="#2e8b57"><b>char</b></font> *dest, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *source,
<font color="#2e8b57"><b>size_t</b></font> size);
<font color="#0000ff">// Appends "size" bytes of "source" to "dest". Assumes</font>
<font color="#0000ff">// that there is enough room remaining in "dest" to</font>
<font color="#0000ff">// accommodate the new string.</font>
<font color="#0000ff">// Returns a pointer to "dest".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *append(<font color="#2e8b57"><b>char</b></font> *dest, <font color="#2e8b57"><b>int32_t</b></font> number);
<font color="#0000ff">// Converts "number" to a string and appends it to</font>
<font color="#0000ff">// "dest". Assumes that there is enough room remaining</font>
<font color="#0000ff">// in "dest" to accommodate the new string.</font>
<font color="#0000ff">// Returns a pointer to "dest".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *append(<font color="#2e8b57"><b>char</b></font> *dest, <font color="#2e8b57"><b>uint32_t</b></font> number);
<font color="#0000ff">// Converts "number" to a string and appends it to</font>
<font color="#0000ff">// "dest". Assumes that there is enough room remaining</font>
<font color="#0000ff">// in "dest" to accommodate the new string.</font>
<font color="#0000ff">// Returns a pointer to "dest".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *append(<font color="#2e8b57"><b>char</b></font> *dest, <font color="#2e8b57"><b>double</b></font> number);
<font color="#0000ff">// Converts "number" to a string and appends it to</font>
<font color="#0000ff">// "dest". Assumes that there is enough room remaining</font>
<font color="#0000ff">// in "dest" to accommodate the new string.</font>
<font color="#0000ff">// Returns a pointer to "dest".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *append(<font color="#2e8b57"><b>char</b></font> *dest, <font color="#2e8b57"><b>double</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> scale);
<font color="#0000ff">// Converts "number" to a string using "scale" and</font>
<font color="#0000ff">// appends it to "dest". Assumes that there is enough</font>
<font color="#0000ff">// room remaining in "dest" to accommodate the new</font>
<font color="#0000ff">// string. Returns a pointer to "dest".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *append(<font color="#2e8b57"><b>char</b></font> *dest, <font color="#2e8b57"><b>double</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> precision,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> scale);
<font color="#0000ff">// Converts "number" to a string using "precision" and</font>
<font color="#0000ff">// "scale" and appends it to "dest". Assumes that there</font>
<font color="#0000ff">// is enough room remaining in "dest" to accommodate</font>
<font color="#0000ff">// the new string. Returns a pointer to "dest".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *copy(<font color="#2e8b57"><b>char</b></font> *dest, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *source);
<font color="#0000ff">// Replaces "dest" with "source". Assumes that there</font>
<font color="#0000ff">// is enough room in "dest" to accommodate "source".</font>
<font color="#0000ff">// Returns a pointer to "dest".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *copy(<font color="#2e8b57"><b>char</b></font> *dest,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *source, <font color="#2e8b57"><b>size_t</b></font> size);
<font color="#0000ff">// Replaces the first "size" bytes of "dest" with</font>
<font color="#0000ff">// "source". Assumes that "dest" is at least "size"</font>
<font color="#0000ff">// bytes long.</font>
<font color="#0000ff">// Returns a pointer to "dest".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *copy(<font color="#2e8b57"><b>char</b></font> *dest, <font color="#2e8b57"><b>size_t</b></font> location,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *source);
<font color="#0000ff">// Replaces "dest" with "source", starting "location"</font>
<font color="#0000ff">// bytes into "dest". Assumes that there is enough</font>
<font color="#0000ff">// room in "dest" (after "location" bytes) to</font>
<font color="#0000ff">// accommodate "source".</font>
<font color="#0000ff">// Returns a pointer to "dest".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *copy(<font color="#2e8b57"><b>char</b></font> *dest, <font color="#2e8b57"><b>size_t</b></font> location,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *source, <font color="#2e8b57"><b>size_t</b></font> size);
<font color="#0000ff">// Replaces "size" bytes of "dest" with "source",</font>
<font color="#0000ff">// starting "location" bytes into "dest". Assumes that</font>
<font color="#0000ff">// there are "size" bytes in "dest" (after "location"</font>
<font color="#0000ff">// bytes).</font>
<font color="#0000ff">// Returns a pointer to "dest".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int</b></font> compare(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str1, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str2);
<font color="#0000ff">// Returns -1,0 or 1 if "str1" is greater than, </font>
<font color="#0000ff">// equal to or less than "str2".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int</b></font> compare(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str1, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str2,
<font color="#2e8b57"><b>size_t</b></font> size);
<font color="#0000ff">// Returns -1,0 or 1 if "size" bytes of "str1" are</font>
<font color="#0000ff">// greater than, equal to or less than "size" bytes of</font>
<font color="#0000ff">// "str2".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int</b></font> compareIgnoringCase(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str1,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str2);
<font color="#0000ff">// Returns -1,0 or 1 if "str1" is greater than, </font>
<font color="#0000ff">// equal to or less than "str2", ignoring case.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int</b></font> compareIgnoringCase(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str1,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str2,
<font color="#2e8b57"><b>size_t</b></font> size);
<font color="#0000ff">// Returns -1,0 or 1 if "size" bytes of "str1" are</font>
<font color="#0000ff">// greater than, equal to or less than "size" bytes of</font>
<font color="#0000ff">// "str2", ignoring case.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>bool</b></font> contains(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *haystack,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *needle);
<font color="#0000ff">// Returns true if "haystack" contains "needle" or</font>
<font color="#0000ff">// false otherwise.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>bool</b></font> contains(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *haystack, <font color="#2e8b57"><b>char</b></font> needle);
<font color="#0000ff">// Returns true if "haystack" contains "needle" or</font>
<font color="#0000ff">// false otherwise.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *findFirst(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *haystack,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *needle);
<font color="#0000ff">// Returns a pointer to the first occurrance of "needle"</font>
<font color="#0000ff">// in "haystack" or NULL if not found.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *findFirst(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *haystack,
<font color="#2e8b57"><b>char</b></font> needle);
<font color="#0000ff">// Returns a pointer to the first occurrance of "needle"</font>
<font color="#0000ff">// in "haystack" or NULL if not found.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *findLast(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *haystack,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *needle);
<font color="#0000ff">// Returns a pointer to the last occurrance of "needle"</font>
<font color="#0000ff">// in "haystack" or NULL if not found.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *findLast(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *haystack,
<font color="#2e8b57"><b>char</b></font> needle);
<font color="#0000ff">// Returns a pointer to the last occurrance of "needle"</font>
<font color="#0000ff">// in "haystack" or NULL if not found.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *findFirst(<font color="#2e8b57"><b>char</b></font> *haystack, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *needle);
<font color="#0000ff">// Returns a pointer to the first occurrance of "needle"</font>
<font color="#0000ff">// in "haystack" or NULL if not found.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *findFirst(<font color="#2e8b57"><b>char</b></font> *haystack, <font color="#2e8b57"><b>char</b></font> needle);
<font color="#0000ff">// Returns a pointer to the first occurrance of "needle"</font>
<font color="#0000ff">// in "haystack" or NULL if not found.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *findLast(<font color="#2e8b57"><b>char</b></font> *haystack, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *needle);
<font color="#0000ff">// Returns a pointer to the last occurrance of "needle"</font>
<font color="#0000ff">// in "haystack" or NULL if not found.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *findLast(<font color="#2e8b57"><b>char</b></font> *haystack, <font color="#2e8b57"><b>char</b></font> needle);
<font color="#0000ff">// Returns a pointer to the last occurrance of "needle"</font>
<font color="#0000ff">// in "haystack" or NULL if not found.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *findFirstOfSet(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *haystack,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *set);
<font color="#0000ff">// Returns a pointer to the first occurence in</font>
<font color="#0000ff">// "haystack" of any of the characters in "set".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *findFirstOfSet(<font color="#2e8b57"><b>char</b></font> *haystack,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *set);
<font color="#0000ff">// Returns a pointer to the first occurence in</font>
<font color="#0000ff">// "haystack" of any of the characters in "set".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>size_t</b></font> lengthContainingSet(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *haystack,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *set);
<font color="#0000ff">// Returns the number of characters, starting at the</font>
<font color="#0000ff">// beginning of "haystack" which consists entirely of</font>
<font color="#0000ff">// characters in "set".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>size_t</b></font> lengthNotContainingSet(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *haystack,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *set);
<font color="#0000ff">// Returns the number of characters, starting at the</font>
<font color="#0000ff">// beginning of "haystack" which consists entirely of</font>
<font color="#0000ff">// characters not in "set".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *duplicate(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str);
<font color="#0000ff">// Creates a duplicate of "str" and returns a pointer</font>
<font color="#0000ff">// to it. Note that this method allocates a buffer for</font>
<font color="#0000ff">// the duplicate string internally and returns it. The</font>
<font color="#0000ff">// calling program must deallocate this buffer.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *duplicate(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str, <font color="#2e8b57"><b>size_t</b></font> length);
<font color="#0000ff">// Creates a duplicate of the first "length" bytes of</font>
<font color="#0000ff">// "str" and returns a pointer to it. Note that this</font>
<font color="#0000ff">// method allocates a buffer for the duplicate string</font>
<font color="#0000ff">// internally and returns it. The calling program must</font>
<font color="#0000ff">// deallocate this buffer.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> upper(<font color="#2e8b57"><b>char</b></font> *str);
<font color="#0000ff">// Converts "str" to uppercase.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> lower(<font color="#2e8b57"><b>char</b></font> *str);
<font color="#0000ff">// Converts "str" to lowercase.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> rightTrim(<font color="#2e8b57"><b>char</b></font> *str);
<font color="#0000ff">// Rrims all spaces off of the right hand side of "str".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> rightTrim(<font color="#2e8b57"><b>char</b></font> *str, <font color="#2e8b57"><b>char</b></font> character);
<font color="#0000ff">// Rrims all "character"'s off of the right hand side</font>
<font color="#0000ff">// of "str".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> leftTrim(<font color="#2e8b57"><b>char</b></font> *str);
<font color="#0000ff">// Trims all spaces off of the left hand side of "str".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> leftTrim(<font color="#2e8b57"><b>char</b></font> *str, <font color="#2e8b57"><b>char</b></font> character);
<font color="#0000ff">// Trims all "character"'s off of the left hand side</font>
<font color="#0000ff">// of "str".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> bothTrim(<font color="#2e8b57"><b>char</b></font> *str);
<font color="#0000ff">// Trims all spaces off of both sides of "str".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> bothTrim(<font color="#2e8b57"><b>char</b></font> *str, <font color="#2e8b57"><b>char</b></font> character);
<font color="#0000ff">// Trims all characters off of both sides of "str".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> strip(<font color="#2e8b57"><b>char</b></font> *str, <font color="#2e8b57"><b>char</b></font> character);
<font color="#0000ff">// Strips all instances of "character" from "str".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> strip(<font color="#2e8b57"><b>char</b></font> *str1, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str2);
<font color="#0000ff">// Strips all instances of "str2" from "str1".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int</b></font> integerLength(<font color="#2e8b57"><b>int16_t</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int</b></font> integerLength(<font color="#2e8b57"><b>int32_t</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int</b></font> integerLength(<font color="#2e8b57"><b>int64_t</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int</b></font> integerLength(<font color="#2e8b57"><b>uint16_t</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int</b></font> integerLength(<font color="#2e8b57"><b>uint32_t</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int</b></font> integerLength(<font color="#2e8b57"><b>uint64_t</b></font> number);
<font color="#0000ff">// Returns the number of characters needed to represent</font>
<font color="#0000ff">// "number" as a string.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>bool</b></font> isInteger(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *val);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>bool</b></font> isInteger(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *val, <font color="#2e8b57"><b>int</b></font> size);
<font color="#0000ff">// Returns true if the string "val" is an integer and</font>
<font color="#0000ff">// false if it is not an integer.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>bool</b></font> isNumber(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *val);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>bool</b></font> isNumber(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *val, <font color="#2e8b57"><b>int</b></font> size);
<font color="#0000ff">// Returns true the string "val" is a number and false</font>
<font color="#0000ff">// if it is not a number</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>int16_t</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>uint16_t</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>int16_t</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> zeropadding);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>uint16_t</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> zeropadding);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>int32_t</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>uint32_t</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>int32_t</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> zeropadding);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>uint32_t</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> zeropadding);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>int64_t</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>uint64_t</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>int64_t</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> zeropadding);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>uint64_t</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> zeropadding);
<font color="#0000ff">// Returns a string representing "number". The string</font>
<font color="#0000ff">// is allocated inside the function and must be deleted</font>
<font color="#0000ff">// by the calling program.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>float</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>float</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> scale);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>float</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> precision,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> scale);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>double</b></font> number);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>double</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> scale);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *parseNumber(<font color="#2e8b57"><b>double</b></font> number,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> precision,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>short</b></font> scale);
<font color="#0000ff">// Returns a string representing "number". The string</font>
<font color="#0000ff">// is allocated inside the function and must be deleted</font>
<font color="#0000ff">// by the calling program.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int64_t</b></font> toInteger(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string);
<font color="#0000ff">// Converts "string" to a 64-bit integer.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int64_t</b></font> toInteger(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string, <font color="#2e8b57"><b>char</b></font> **endptr);
<font color="#0000ff">// Converts "string" to a 64-bit integer. If non-NULL,</font>
<font color="#0000ff">// endptr will be set to the first character in the</font>
<font color="#0000ff">// string after the number.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int64_t</b></font> toInteger(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string, <font color="#2e8b57"><b>int</b></font> base);
<font color="#0000ff">// Converts "string" to a 64-bit integer of base "base".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int64_t</b></font> toInteger(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string,
<font color="#2e8b57"><b>char</b></font> **endptr, <font color="#2e8b57"><b>int</b></font> base);
<font color="#0000ff">// Converts "string" to a 64-bit integer of base "base".</font>
<font color="#0000ff">// If non-NULL, endptr will be set to the first</font>
<font color="#0000ff">// character in the string after the number.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>uint64_t</b></font> toUnsignedInteger(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string);
<font color="#0000ff">// Converts "string" to a 64-bit unsigned integer.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>uint64_t</b></font> toUnsignedInteger(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string,
<font color="#2e8b57"><b>char</b></font> **endptr);
<font color="#0000ff">// Converts "string" to a 64-bit unsigned integer. If</font>
<font color="#0000ff">// non-NULL, endptr will be set to the first character</font>
<font color="#0000ff">// in the string after the number.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>uint64_t</b></font> toUnsignedInteger(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string,
<font color="#2e8b57"><b>int</b></font> base);
<font color="#0000ff">// Converts "string" to a 64-bit unsigned integer of</font>
<font color="#0000ff">// base "base".</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>uint64_t</b></font> toUnsignedInteger(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string,
<font color="#2e8b57"><b>char</b></font> **endptr,
<font color="#2e8b57"><b>int</b></font> base);
<font color="#0000ff">// Converts "string" to a 64-bit unsigned integer of</font>
<font color="#0000ff">// base "base".</font>
<font color="#0000ff">// If non-NULL, endptr will be set to the first</font>
<font color="#0000ff">// character in the string after the number.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>long</b></font> <font color="#2e8b57"><b>double</b></font> toFloat(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string);
<font color="#0000ff">// Converts "string" to a floating point number.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>long</b></font> <font color="#2e8b57"><b>double</b></font> toFloat(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string,
<font color="#2e8b57"><b>char</b></font> **endptr);
<font color="#0000ff">// Converts "string" to a floating point number. If</font>
<font color="#0000ff">// non-NULL, endptr will be set to the first character</font>
<font color="#0000ff">// in the string after the number.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *httpEscape(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *input);
<font color="#0000ff">// http escapes "input" and returns it in a buffer</font>
<font color="#0000ff">// allocated inside the function. This buffer must be</font>
<font color="#0000ff">// deleted by the calling program.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *escape(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *input,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *characters);
<font color="#0000ff">// escapes all characters in "characters" found in</font>
<font color="#0000ff">// "input" using \'s and returns it in a buffer</font>
<font color="#0000ff">// allocated inside the function. This buffer must be</font>
<font color="#0000ff">// deleted by the calling program.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *unescape(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *input);
<font color="#0000ff">// unescapes all \-escaped characters found in</font>
<font color="#0000ff">// "input" and returns the result in a buffer</font>
<font color="#0000ff">// allocated inside the function. This buffer must be</font>
<font color="#0000ff">// deleted by the calling program.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> escape(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *input, <font color="#2e8b57"><b>uint64_t</b></font> inputsize,
<font color="#2e8b57"><b>char</b></font> **output, <font color="#2e8b57"><b>uint64_t</b></font> *outputsize,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *characters);
<font color="#0000ff">// similar to escape() above, but takes an "inputsize"</font>
<font color="#0000ff">// parameter and returns the result in "output" and</font>
<font color="#0000ff">// "outputsize" rather than in a return value</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> unescape(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *input, <font color="#2e8b57"><b>uint64_t</b></font> inputsize,
<font color="#2e8b57"><b>char</b></font> **output, <font color="#2e8b57"><b>uint64_t</b></font> *outputsize);
<font color="#0000ff">// similar to unescape() above, but takes an "inputsize"</font>
<font color="#0000ff">// parameter and returns the result in "output" and</font>
<font color="#0000ff">// "outputsize" rather than in a return value</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *base64Encode(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *input);
<font color="#0000ff">// base64-encodes "input" and returns it in a buffer</font>
<font color="#0000ff">// allocated inside the function. This buffer must be</font>
<font color="#0000ff">// deleted by the calling program.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *base64Encode(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *input,
<font color="#2e8b57"><b>uint64_t</b></font> inputsize);
<font color="#0000ff">// similar to base64Encode above but only encodes</font>
<font color="#0000ff">// the first "inputsize" characters of "input"</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> base64Encode(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *input,
<font color="#2e8b57"><b>uint64_t</b></font> inputsize,
<font color="#2e8b57"><b>char</b></font> **output,
<font color="#2e8b57"><b>uint64_t</b></font> *outputsize);
<font color="#0000ff">// similar to base64Encode() above, but returns the</font>
<font color="#0000ff">// result in "output" and "outputsize" rather than in a</font>
<font color="#0000ff">// return value</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *base64Decode(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *input);
<font color="#0000ff">// base64-decodes "input" and returns it in a buffer</font>
<font color="#0000ff">// allocated inside the function. This buffer must be</font>
<font color="#0000ff">// deleted by the calling program.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *base64Decode(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *input,
<font color="#2e8b57"><b>uint64_t</b></font> inputsize);
<font color="#0000ff">// similar to base64Decode above but only decodes</font>
<font color="#0000ff">// the first "inputsize" characters of "input"</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> base64Decode(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *input,
<font color="#2e8b57"><b>uint64_t</b></font> inputsize,
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> **output,
<font color="#2e8b57"><b>uint64_t</b></font> *outputsize);
<font color="#0000ff">// similar to base64Decode() above, but returns the</font>
<font color="#0000ff">// result in "output" and "outputsize" rather than in a</font>
<font color="#0000ff">// return value</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> leftJustify(<font color="#2e8b57"><b>char</b></font> *str, <font color="#2e8b57"><b>int</b></font> length);
<font color="#0000ff">// Moves leading spaces to the end of "str" for</font>
<font color="#0000ff">// "length" characters.</font>
<font color="#0000ff">// </font>
<font color="#0000ff">// Example:</font>
<font color="#0000ff">// " hello " -> "hello "</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> rightPad(<font color="#2e8b57"><b>char</b></font> *str, <font color="#2e8b57"><b>int</b></font> lngth,
<font color="#2e8b57"><b>char</b></font> padchar, <font color="#2e8b57"><b>bool</b></font> fill);
<font color="#0000ff">// Moves trailing spaces to the beginning of "str" for</font>
<font color="#0000ff">// "length" characters and replaces them with the</font>
<font color="#0000ff">// padchar.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Example when padchar is X:</font>
<font color="#0000ff">// "hello " -> "XXXXXXhello"</font>
<font color="#0000ff">// Example when padchar is X and lngth is 10 and fill</font>
<font color="#0000ff">// is true</font>
<font color="#0000ff">// "hello" -> "XXXXhello"</font>
<font color="#0000ff">// Example when padchar is X and lngth is 10 and fill</font>
<font color="#0000ff">// is false</font>
<font color="#0000ff">// "hello " -> " hello"</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> rightJustify(<font color="#2e8b57"><b>char</b></font> *str, <font color="#2e8b57"><b>int</b></font> length);
<font color="#0000ff">// Moves trailing spaces to the beginning of "str" for</font>
<font color="#0000ff">// "length" characters.</font>
<font color="#0000ff">// </font>
<font color="#0000ff">// Example:</font>
<font color="#0000ff">// " hello " -> " hello"</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> center(<font color="#2e8b57"><b>char</b></font> *str, <font color="#2e8b57"><b>int</b></font> length);
<font color="#0000ff">// Centers the text of "str" for "length" characters.</font>
<font color="#0000ff">// </font>
<font color="#0000ff">// Example:</font>
<font color="#0000ff">// "hello " -> " hello "</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> safePrint(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str);
<font color="#0000ff">// Prints "str", however all non-printing characters</font>
<font color="#0000ff">// are printed as hex values of the format: (0x0a) and</font>
<font color="#0000ff">// carriage returns, line feeds and tabs are printed</font>
<font color="#0000ff">// as \n, \r and \t.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> safePrint(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str, <font color="#2e8b57"><b>int</b></font> length);
<font color="#0000ff">// safePrint()'s "length" characters of "str" </font>
<font color="#0000ff">// These methods parse "string" delimited by "delimiter"</font>
<font color="#0000ff">// and allocate "listlength" elements of "list" to return the</font>
<font color="#0000ff">// parts. Each member of "list" and "list" must be deallocated</font>
<font color="#0000ff">// by the calling program. In the versions of the method</font>
<font color="#0000ff">// where "stringlength" or "delimiterlength" are not</font>
<font color="#0000ff">// supplied, string and/or delimiter are presumed to be</font>
<font color="#0000ff">// NULL terminated strings.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> split(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string,
<font color="#2e8b57"><b>ssize_t</b></font> stringlength,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *delimiter,
<font color="#2e8b57"><b>ssize_t</b></font> delimiterlength,
<font color="#2e8b57"><b>bool</b></font> collapse,
<font color="#2e8b57"><b>char</b></font> ***list,
<font color="#2e8b57"><b>uint64_t</b></font> *listlength);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> split(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *delimiter,
<font color="#2e8b57"><b>ssize_t</b></font> delimiterlength,
<font color="#2e8b57"><b>bool</b></font> collapse,
<font color="#2e8b57"><b>char</b></font> ***list,
<font color="#2e8b57"><b>uint64_t</b></font> *listlength);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> split(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string,
<font color="#2e8b57"><b>ssize_t</b></font> stringlength,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *delimiter,
<font color="#2e8b57"><b>bool</b></font> collapse,
<font color="#2e8b57"><b>char</b></font> ***list,
<font color="#2e8b57"><b>uint64_t</b></font> *listlength);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font> split(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *delimiter,
<font color="#2e8b57"><b>bool</b></font> collapse,
<font color="#2e8b57"><b>char</b></font> ***list,
<font color="#2e8b57"><b>uint64_t</b></font> *listlength);
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *subString(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *str,
<font color="#2e8b57"><b>size_t</b></font> start, <font color="#2e8b57"><b>size_t</b></font> end);
<font color="#0000ff">// Returns a copy of the segment of "str"</font>
<font color="#0000ff">// between string indices "start" and "end".</font>
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/charstring.h></font>
};
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>
<font color="#a020f0">#endif</font>
</pre>
</body>
</html>
|