5 // Created by Terrin Eager on 9/26/12.
19 BJString::BJString(const BJString& scr)
25 BJString::BJString(const char* str)
39 BJString& BJString::operator=(const char* str)
45 BJString& BJString::operator=(const BJString& str)
50 bool BJString::operator==(const char* str)
52 if (buffer == NULL && str == NULL)
54 if (buffer == NULL || str == NULL)
57 return (strcmp(str,buffer) == 0);
59 bool BJString::operator==(const BJString& str)
61 if (buffer == NULL && str.GetBuffer() == NULL)
63 if (buffer == NULL || str.GetBuffer() == NULL)
65 return (strcmp(str.GetBuffer(),buffer) == 0);
68 bool BJString::operator<(const BJString& str) const
70 const char* myBuff = GetBuffer();
71 const char* otherBuff = str.GetBuffer();
73 if (myBuff == NULL && otherBuff == NULL)
75 if (myBuff != NULL && otherBuff == NULL)
77 if (myBuff == NULL && otherBuff != NULL)
80 int cmp = strcmp(myBuff, otherBuff);
89 BJ_COMPARE BJString::Compare(const BJString& str)
91 const char* myBuff = GetBuffer();
92 const char* otherBuff = str.GetBuffer();
94 if (myBuff == NULL && otherBuff == NULL)
96 if (myBuff != NULL && otherBuff == NULL)
98 if (myBuff == NULL && otherBuff != NULL)
101 int cmp = strcmp(myBuff, otherBuff);
112 BJString& BJString::operator+=(const char* str)
115 return operator=(str);
119 BJString temp = buffer;
120 Create((BJ_UINT32)(strlen(buffer) + strlen(str)));
121 strcpy(buffer,temp.GetBuffer());
125 BJString& BJString::operator+=(const BJString&str)
127 operator+=(str.GetBuffer());
132 const char* BJString::GetBuffer() const
137 void BJString::Set(const char* str)
140 BJ_UINT32 len = str?(BJ_UINT32)strlen(str):0;
148 void BJString::Set(const char* str, BJ_UINT32 len)
154 strncpy(buffer, str, len);
156 memset(buffer, 0, length);
160 void BJString::Append(const char* str, BJ_UINT32 len)
162 if (length < (strlen(buffer) + strlen(str)))
164 BJString temp = buffer;
165 Create((BJ_UINT32)(strlen(buffer) + strlen(str)));
166 if (buffer && temp.buffer)
167 strcpy(buffer,temp.GetBuffer());
169 strncat(buffer,str,len);
172 bool BJString::Contains(const char* str)
174 if (buffer == NULL && str == NULL)
176 if (buffer == NULL || str == NULL)
178 return (strstr(buffer,str) != NULL);
181 BJ_UINT32 BJString::GetUINT32()
189 void BJString::Format(BJ_UINT64 number,BJ_FORMAT_STYLE style)
194 sprintf(buffer,"%llu",number);
198 char formatedTime[24];
199 time_t timeValue = number;
200 struct tm* timeStruct = localtime(&timeValue);
201 strftime(formatedTime, sizeof(formatedTime), "%Y-%m-%d_%T_%a", timeStruct);
211 void BJString::Create(BJ_UINT32 len)
216 memset(buffer, 0, len+1);
227 buffer = new char[len+1];
230 memset(buffer, 0, len+1);
235 BJ_UINT32 BJString::GetLength()
237 return buffer?(BJ_UINT32)strlen(buffer):0;