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
|
// Copyright (c) 2001 David Muse
// See the file COPYING for more information
#include <rudiments/charstring.h>
#include <stdio.h>
#include <string.h>
int main(int argc, const char **argv) {
// initialize a text buffer and print it out
char buffer[100];
charstring::copy(buffer," hello there buddy ");
printf("!%s!\n",buffer);
// trim the spaces off of the right hand side
charstring::rightTrim(buffer);
printf("!%s!\n",buffer);
// trim the spaces off of the left hand side
charstring::leftTrim(buffer);
printf("!%s!\n",buffer);
// strip the spaces out
charstring::copy(buffer," hello there buddy ");
charstring::strip(buffer,' ');
printf("!%s!\n",buffer);
// strip the " " out
charstring::copy(buffer," hello there buddy ");
charstring::strip(buffer," ");
printf("!%s!\n",buffer);
// convert buffer to uppercase
charstring::upper(buffer);
printf("!%s!\n",buffer);
// convert buffer to lowercase
charstring::lower(buffer);
printf("!%s!\n",buffer);
// http escape the buffer
char *escbuffer=charstring::httpEscape("!@#$%^&*()hello-+");
printf("!@#$\\%^&*()hello-+ http escaped is %s\n",escbuffer);
delete escbuffer;
// evaluate a string to see if it's a number
if (charstring::isNumber("-100.5")) {
printf("-100.5 is a number\n");
}
if (!charstring::isNumber("-100.5.10")) {
printf("-100.5.10 is not a number\n");
}
// evaluate a string to see if it's an integer
if (charstring::isInteger("-100")) {
printf("-100 is an integer\n");
}
if (!charstring::isInteger("-100.5")) {
printf("-100.5.10 is not an integer\n");
}
// create a new string containing text surrounded by spaces
char hello[16];
charstring::copy(hello," hello ");
printf("|%s|\n",hello);
// left justify the text
charstring::leftJustify(hello,15);
printf("|%s|\n",hello);
// right justify the text
charstring::rightJustify(hello,15);
printf("|%s|\n",hello);
// center the text over and over...
charstring::copy(hello,"hello ");
charstring::center(hello,15);
printf("|%s|\n",hello);
charstring::copy(hello," hello ");
charstring::center(hello,15);
printf("|%s|\n",hello);
charstring::copy(hello," hello ");
charstring::center(hello,15);
printf("|%s|\n",hello);
charstring::copy(hello," hello ");
charstring::center(hello,15);
printf("|%s|\n",hello);
charstring::copy(hello," hello ");
charstring::center(hello,15);
printf("|%s|\n",hello);
charstring::copy(hello," hello ");
charstring::center(hello,15);
printf("|%s|\n",hello);
charstring::copy(hello," hello ");
charstring::center(hello,15);
printf("|%s|\n",hello);
charstring::copy(hello," hello ");
charstring::center(hello,15);
printf("|%s|\n",hello);
charstring::copy(hello," hello ");
charstring::center(hello,15);
printf("|%s|\n",hello);
charstring::copy(hello," hello ");
charstring::center(hello,15);
printf("|%s|\n",hello);
charstring::copy(hello," hello");
charstring::center(hello,15);
printf("|%s|\n",hello);
// print the number of bytes necessary to store each number as a string
printf("size of 1 is: %d\n",charstring::integerLength(1));
printf("size of 10 is: %d\n",charstring::integerLength(10));
printf("size of 100 is: %d\n",charstring::integerLength(100));
printf("size of 1000 is: %d\n",charstring::integerLength(1000));
printf("size of -1 is: %d\n",charstring::integerLength(-1));
printf("size of -10 is: %d\n",charstring::integerLength(-10));
printf("size of -100 is: %d\n",charstring::integerLength(-100));
printf("size of -1000 is: %d\n",charstring::integerLength(-1000));
}
|