STRING Class Reference

#include <strngs.h>

List of all members.


Detailed Description

All you ever wanted to do to strings.

Definition at line 31 of file strngs.h.

Public Member Functions

Private Attributes


Constructor & Destructor Documentation

STRING::STRING (  )  [inline]

Definition at line 36 of file strngs.h.

References NULL.

00036              {  //constructor
00037       ptr = NULL;                //empty string
00038     }

STRING::STRING ( const STRING string  )  [inline]

Definition at line 40 of file strngs.h.

References alloc_string(), NULL, and ptr.

00041                                  {
00042       if (string.ptr != NULL) {
00043                                  //length of source
00044         INT32 length = strlen (string.ptr) + 1;
00045 
00046                                  //get space
00047         ptr = alloc_string (length);
00048         strcpy (ptr, string.ptr);//and copy it
00049       }
00050       else {
00051         ptr = alloc_string (1);
00052         if (ptr != NULL)
00053           *ptr = '\0';
00054       }
00055     }

STRING::STRING ( const char *  string  )  [inline]

Definition at line 57 of file strngs.h.

References alloc_string(), and NULL.

00058                                {
00059       if (string != NULL) {
00060                                  //length of source
00061         INT32 length = strlen (string) + 1;
00062 
00063                                  //get space
00064         ptr = alloc_string (length);
00065         if (ptr != NULL)
00066           strcpy(ptr, string);  //and copy it
00067       }
00068       else {
00069         ptr = alloc_string (1);
00070         if (ptr != NULL)
00071           *ptr = '\0';
00072       }
00073     }

STRING::~STRING (  )  [inline]

Definition at line 75 of file strngs.h.

References free_string(), and NULL.

00075                {                 //destructor
00076       if (ptr != NULL)
00077         free_string(ptr);  //give it back
00078     }


Member Function Documentation

BOOL8 STRING::contains ( const char  c  )  const [inline]

Definition at line 86 of file strngs.h.

References FALSE, NULL, and TRUE.

Referenced by eval_word_spacing(), and uniformly_spaced().

00087                                        {
00088       if ((ptr == NULL) || ((c != '\0') && strchr (ptr, c) == NULL))
00089         return FALSE;
00090       else
00091         return TRUE;
00092     }

void STRING::de_dump ( FILE *  f  )  [inline]

Definition at line 170 of file strngs.h.

References de_serialise_bytes(), free_mem(), and NULL.

Referenced by WERD::de_dump().

00171                           {
00172       char *instring;            //input from read
00173 
00174       instring = (char *) de_serialise_bytes (f, (ptrdiff_t) ptr);
00175       ptr = NULL;
00176       *this = instring;
00177       free_mem(instring);
00178     }

void STRING::dump ( FILE *  f  )  [inline]

Definition at line 165 of file strngs.h.

References serialise_bytes().

Referenced by WERD::dump().

00166                        {
00167       serialise_bytes (f, (void *) ptr, (int) (length () + 1));
00168     }

INT32 STRING::length (  )  const [inline]

Definition at line 94 of file strngs.h.

References NULL.

Referenced by insert_rej_cblobs(), LEAF_MENU_NODE::max_num_chars(), NON_LEAF_MENU_NODE::max_num_chars(), operator+(), operator+=(), operator=(), recog_word_recursive(), smd_cmd(), write_cooked_text(), and write_shm_text().

00094                          {  //string length
00095       if (ptr != NULL)
00096         return strlen (ptr);
00097       else
00098         return 0;
00099     }

BOOL8 STRING::operator!= ( const char *  string  )  const [inline]

Definition at line 125 of file strngs.h.

References NULL.

00127     {
00128       if (ptr != NULL && string != NULL)
00129         return strcmp (ptr, string) != 0;
00130       else
00131         return !((ptr == NULL || *ptr == '\0')
00132           && (string == NULL || *string == '\0'));
00133     }

BOOL8 STRING::operator!= ( const STRING string  )  const [inline]

Definition at line 115 of file strngs.h.

References NULL, and ptr.

00117     {
00118       if (ptr != NULL && string.ptr != NULL)
00119         return strcmp (ptr, string.ptr) != 0;
00120       else
00121         return !((ptr == NULL || *ptr == '\0')
00122           && (string.ptr == NULL || *(string.ptr) == '\0'));
00123     }

STRING STRING::operator+ ( const char  ch  )  const

Concatenate/append char to STRING.

Definition at line 106 of file strngs.cpp.

References alloc_string(), length(), NULL, ptr, and tprintf().

00109 {
00110   INT32 length;                  //length of 1st op
00111   STRING result;                 //concatenated string
00112 
00113   if (ptr == NULL)
00114     length = 0;
00115   else
00116     length = strlen (ptr);
00117                                  //total length
00118   result.ptr = alloc_string (length + 2);
00119   if (result.ptr == NULL) {
00120     tprintf ("No memory to allocate string");
00121     return result;
00122   }
00123   if (ptr != NULL)
00124     strcpy (result.ptr, ptr);
00125   result.ptr[length] = ch;       //put together
00126   result.ptr[length + 1] = '\0';
00127   return result;
00128 }

STRING STRING::operator+ ( const STRING string  )  const

Concatenate two STRINGs.

Definition at line 74 of file strngs.cpp.

References alloc_string(), length(), NULL, ptr, string(), and tprintf().

00077 {
00078   INT32 length;                  //length of 1st op
00079   STRING result;                 //concatenated string
00080 
00081   if (ptr == NULL)
00082     length = 0;
00083   else
00084     length = strlen (ptr);
00085   result.ptr = alloc_string (length + strlen (string.ptr) + 1);
00086   //total length
00087   if (result.ptr == NULL) {
00088     tprintf ("No memory to allocate string");
00089     return result;
00090   }
00091   result.ptr[0] = '\0';
00092   if (ptr != NULL)
00093     strcpy (result.ptr, ptr);
00094   if (string.ptr != NULL)
00095                                  //put together
00096     strcpy (result.ptr + length, string.ptr);
00097   return result;
00098 }

STRING & STRING::operator+= ( const char  ch  ) 

Concatenate a char to a string, putting the result straing back in the string

Definition at line 172 of file strngs.cpp.

References alloc_string(), free_string(), length(), NULL, ptr, and tprintf().

00174   {
00175   INT32
00176     length;                      //length of 1st op
00177   char *
00178     src;                         //source string
00179 
00180   if (ch == '\0')
00181     return *this;                //unchanged
00182   if (ptr == NULL)
00183     length = 0;
00184   else
00185     length = strlen (ptr);       //length of 1st op
00186   src = ptr;                     //temp copy
00187                                  //new length
00188   ptr = alloc_string (length + 2);
00189   if (ptr == NULL) {
00190     tprintf ("No memory to allocate string");
00191     ptr = src;
00192     return *this;
00193   }
00194   if (src != NULL) {
00195     strcpy(ptr, src);  //copy old
00196     free_string(src);  //free old one
00197   }
00198   ptr[length] = ch;              //add new char
00199   ptr[length + 1] = '\0';
00200   return *this;
00201 }

STRING& STRING::operator+= ( const STRING string  )  [inline]

Definition at line 152 of file strngs.h.

References ptr.

00153                            {
00154       *this += string.ptr;
00155       return *this;
00156     }

STRING & STRING::operator+= ( const char *  string  ) 

Inplace Concatenate/cat

Concatenate two strings putting the result straing back in the first

Definition at line 137 of file strngs.cpp.

References alloc_string(), free_string(), length(), NULL, ptr, and tprintf().

00139   {
00140   INT32
00141     length;                      //length of 1st op
00142   char *
00143     src;                         //source string
00144 
00145   if (string == NULL || string[0] == '\0')
00146     return *this;                //unchanged
00147   if (ptr == NULL)
00148     length = 0;
00149   else
00150     length = strlen (ptr);       //length of 1st op
00151   src = ptr;                     //temp copy
00152                                  //new length
00153   ptr = alloc_string (length + strlen (string) + 1);
00154   if (ptr == NULL) {
00155     tprintf ("No memory to allocate string");
00156     ptr = src;
00157     return *this;
00158   }
00159   if (src != NULL) {
00160     strcpy(ptr, src);  //copy old
00161     free_string(src);  //free old one
00162   }
00163   strcpy (ptr + length, string); //add new
00164   return *this;
00165 }

STRING& STRING::operator= ( const STRING string  )  [inline]

Definition at line 138 of file strngs.h.

References ptr.

00139                            {     //of string
00140       *this = string.ptr;        //as for char*
00141       return *this;
00142     }

STRING & STRING::operator= ( const char *  string  ) 

Assign a char* to a STRING.

Definition at line 28 of file strngs.cpp.

References alloc_string(), free_string(), length(), NULL, ptr, and tprintf().

00030   {
00031   if (string != NULL) {
00032     INT32
00033       length = strlen (string) + 1;//length of source
00034 
00035     if (ptr == NULL)
00036                                  //get space
00037         ptr = alloc_string (length);
00038                                  //got wrong size
00039     else if (strlen (ptr) != (UINT32) length - 1) {
00040       free_string(ptr);  //free old space
00041                                  //get new space
00042       ptr = alloc_string (length);
00043     }
00044     if (ptr == NULL) {
00045       tprintf ("No memory to allocate string");
00046       return *this;
00047     }
00048     strcpy(ptr, string);  //copy string
00049   }
00050   else {
00051     if (ptr == NULL)
00052       ptr = alloc_string (1);    //get space
00053                                  //got wrong size
00054     else if (strlen (ptr) != 0) {
00055       free_string(ptr);  //free old space
00056       ptr = alloc_string (1);    //get new space
00057     }
00058     if (ptr == NULL) {
00059       tprintf ("No memory to allocate string");
00060       return *this;
00061     }
00062     *ptr = '\0';                 //copy string
00063   }
00064 
00065   return *this;
00066 }

BOOL8 STRING::operator== ( const STRING string  )  const [inline]

Definition at line 105 of file strngs.h.

References NULL, and ptr.

00107     {
00108       if (ptr != NULL && string.ptr != NULL)
00109         return strcmp (ptr, string.ptr) == 0;
00110       else
00111         return (ptr == NULL || *ptr == '\0')
00112           && (string.ptr == NULL || *(string.ptr) == '\0');
00113     }

char& STRING::operator[] ( INT32  index  )  const [inline]

Definition at line 80 of file strngs.h.

00082     {
00083       return ptr[index];         //no bounds checks
00084     }

void STRING::prep_serialise (  )  [inline]

Definition at line 161 of file strngs.h.

Referenced by WERD::prep_serialise().

00161                           {  //set ptrs to counts
00162       ptr = (char *) (length () + 1);
00163     }

const char* STRING::string (  )  const [inline]

Definition at line 101 of file strngs.h.

Referenced by adapt_to_good_ems(), adapt_to_good_samples(), add_event(), apply_boxes(), build_main_var_menu(), build_menu(), check_block_occ(), choice_dump_tester(), classify_word_pass1(), MENU_NODE::cmp_str(), do_view_cmd(), dump_words(), edges_and_textord(), VAR_SUB_MENU::event(), VARIABLE_MENU_LEAF::event(), init_tesseract(), letter_is_okay(), main_setup(), open_outfile(), operator+(), pgeditor_read_file(), NON_LEAF_MENU_NODE::plotx(), LEAF_MENU_NODE::plotx(), STRING_VARIABLE::print(), WERD::print(), read_hpd_file(), read_unlv_file(), read_vec_file(), recog_all_words(), recog_word_recursive(), smd_cmd(), STRING_VARIABLE::string(), WERD::text(), write_cooked_text(), write_map(), and write_results().

00101                                {  //ptr to string
00102       return ptr;
00103     }


Member Data Documentation

char* STRING::ptr [private]

Definition at line 33 of file strngs.h.

Referenced by operator!=(), operator+(), operator+=(), operator=(), operator==(), and STRING().


The documentation for this class was generated from the following files:
Generated on Wed Feb 28 19:49:34 2007 for Tesseract by  doxygen 1.5.1