Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

OSTR.CPP Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

OSTR.CPP

Go to the documentation of this file.
00001 //Filename    : OSTR.CPP
00002 //Description : Object String
00003 
00004 #include <OMISC.H>
00005 #include <CTYPE.H>
00006 #include <OSTR.H>
00007 
00008 //------- Define static variable --------//
00009 
00010 static char work_buf[MAX_STR_LEN+1];
00011 
00012 //-------- Begin of constructor/destructor functions --------//
00013 
00014 String::String() {
00015     str_buf[0] = NULL;
00016 }
00017 
00018 String::String( char *s ) {
00019     strncpy(str_buf, s, MAX_STR_LEN );
00020     str_buf[MAX_STR_LEN] = NULL;
00021 }
00022 
00023 String::String( String& s ) {
00024     memcpy(str_buf, s.str_buf, MAX_STR_LEN+1 );
00025 }
00026 
00027 //---------- End of constructor/destructor functions --------//
00028 
00029 //------- Begin of function String::substr --------//
00036 char* String::substr(int pos, int len) {
00037     work_buf[0] = NULL;
00038 
00039     int strLen = strlen(str_buf);
00040 
00041     if(pos >= strLen)                               // check for boundary errors
00042         return work_buf;
00043 
00044     if( len <= 0 )
00045         len = strLen - pos;
00046     else {
00047         if(len > strLen - pos)
00048             return work_buf;
00049     }
00050 
00051     strncpy( work_buf, str_buf+pos, len );
00052     work_buf[len] = NULL;
00053 
00054     return work_buf;
00055 }
00056 
00057 //------- End of function String::substr ------------//
00058 
00059 //------- Begin of function String::upper/lower -------//
00060 
00061 char* String::upper() {
00062     memcpy( work_buf, str_buf, len()+1 );
00063     strupr( work_buf );
00064 
00065     return work_buf;
00066 }
00067 
00068 char* String::lower(void) {
00069     memcpy( work_buf, str_buf, len()+1 );
00070     strlwr( work_buf );
00071 
00072     return work_buf;
00073 }
00074 
00075 //--------- End of function String::upper/lower --------//
00076 
00077 //-------- Begin of function String::at ---------------//
00084 int String::at(char* searchStr) {
00085     int pos;
00086     char *tmp;
00087 
00088     if( (tmp = strstr(str_buf, searchStr)) != NULL)
00089         pos = (int)(tmp-str_buf);
00090     else
00091         pos = -1;
00092 
00093     return pos;
00094 }
00095 
00096 //---------- End of function String::at ---------------//
00097 
00098 //-------- Begin of operator= functions -----------//
00099 
00100 String& String::operator=(String& s) {
00101     memcpy(str_buf, s.str_buf, MAX_STR_LEN+1 );
00102 
00103     return *this;
00104 }
00105 
00106 String& String::operator=(char *s) {
00107     strncpy(str_buf, s, MAX_STR_LEN );
00108     str_buf[MAX_STR_LEN] = NULL;
00109 
00110     return *this;
00111 }
00112 
00113 String& String::operator=(long value) {
00114     strncpy(str_buf, m.format(value), MAX_STR_LEN );
00115     str_buf[MAX_STR_LEN] = NULL;
00116 
00117     return *this;
00118 }
00119 
00120 //---------- End of operator= functions -----------//
00121 
00122 //-------- Begin of operator+= functions -----------//
00123 
00124 String& String::operator+=(String& s) {
00125     strncat( str_buf, s.str_buf, MAX_STR_LEN );
00126     str_buf[MAX_STR_LEN] = NULL;
00127     return *this;
00128 }
00129 
00130 String& String::operator+=(char *s) {
00131     strncat( str_buf, s, MAX_STR_LEN );
00132     str_buf[MAX_STR_LEN] = NULL;
00133     return *this;
00134 }
00135 
00136 String& String::operator+=(long value) {
00137     strncat( str_buf, m.format(value), MAX_STR_LEN );
00138     str_buf[MAX_STR_LEN] = NULL;
00139     return *this;
00140 }
00141 
00142 //---------- End of operator+= functions -----------//
00143 
00144 //-------- Begin of operator*= functions -----------//
00145 
00146 String& String::operator*=(int n) {
00147     memcpy( work_buf, str_buf, len()+1 );
00148 
00149     for(int i=1; i<n; i++)
00150         strncat(str_buf, work_buf, MAX_STR_LEN);
00151 
00152     str_buf[MAX_STR_LEN] = NULL;
00153 
00154     return *this;
00155 }
00156 
00157 //---------- End of operator*= functions -----------//

Generated on Fri Aug 23 01:38:26 2002 for VirtualU by doxygen1.2.17