00001 /*define for src/common/string.cpp*/ 00002 00003 #ifndef _CORE_COMMON_STRING_HPP 00004 #define _CORE_COMMON_STRING_HPP 00005 00006 /*the string class*/ 00007 class string 00008 { 00009 public: 00010 char *asciiz; /*the string the class owns*/ 00011 uint32 mx_size; /*max buffer capacity*/ 00012 00013 string(); /*init without a string*/ 00014 string(char *str); /*init and set asciiz to str*/ 00015 string(char *str, uint32 size); /*init and copy size bytes from str to asciiz*/ 00016 string (uint32 size); /*init with a size*/ 00017 ~string(); 00018 void inval(); /*leave the string unchanged and set the buffer as empty*/ 00019 char *v(); /*get the string value*/ 00020 00021 uint32 verify(uint32 size); /*realloc to size if buffer's smaller*/ 00022 00023 void set (char *str); /*makes asciiz point at str*/ 00024 void set (char *buff, uint32 size); /*makes the buffer be buff*/ 00025 void nw (uint32 size); /*creates a new buffer*/ 00026 void done(); /*disposes buffer*/ 00027 void copy (char *str); /*copies a string to the buffer*/ 00028 void copy (char *str, uint32 size ); /*no more than size bytes*/ 00029 00030 char *strncat(const char *str); /*concats to the end of asciiz*/ 00031 char *add_char(char ch); /*concats one char*/ 00032 char *cut(uint32 n); /*cuts so the string's length will be n*/ 00033 00034 uint32 length(); /*string length*/ 00035 uint32 strcmp(char *s); /*compare string with asciiz*/ 00036 00037 char *formatText (char *text, char *tokens); /*formats text in a printf manner*/ 00038 00039 uint32 token_count(char div); /*how many tokens, divided by div*/ 00040 char *token(uint32 i, char div); /*returns token #i (first i=0) divided by div. independent from asciiz, have to dispose string manually*/ 00041 00042 char *number (uint32 n, uint32 radix, uint32 n_pos, uint32 zeroes, char zero, uint8 nps); /*sets asciiz to a string with the number n in radix. if zeroes = 1 then 0 fill the space*/ 00043 char *num64 (uint64 n, uint32 radix, uint64 n_pos, uint32 zeroes, char zero, uint8 nps); /*sets asciiz to a string with the number n in radix. if zeroes = 1 then 0 fill the space*/ 00044 char *decim (uint32 n); /*number to string in decimal, no fill zeroes*/ 00045 char *decim(uint32 n, char zero); /*number to string in dec, fill zeroes*/ 00046 char *hex (uint32 n); /*number to string in hex, no fill zeroes*/ 00047 char *hex(uint32 n, char zero); /*number to string in hex, fill zeroes*/ 00048 char *hex(uint32 n, char zero, uint8 pad_size); /*number to string in hex, fill zeroes*/ 00049 00050 uint32 int_val(uint32 radix, uint32 *error); /*returns the value of the string, if non-int then error != 0*/ 00051 }; 00052 00053 uint32 lgth (const char *str); /*regular function for checking string length*/ 00054 uint32 all_chars(char *ch, char c); /*returns 1 if *ch contains only c chars, else 0*/ 00055 uint32 cipher(char ch, uint32 radix); /*return cipher represented in ch in radix, returns DEF_ERROR if incorrect*/ 00056 uint32 str_dif(char *ch1, char *ch2); /*returns first char which differs, 0 if equal*/ 00057 00058 #endif