CzString& CzString::operator+= (float v) { char str[64]; snprintf(str, 64, "%f", v); int len1 = getLength(); int len2 = (int)strlen(str); if (Data == NULL) { allocString(len1 + len2); memcpy(Data, str, len2 + 1); } else { if ((len1 + len2) >= Size) reallocString(len1 + len2); memcpy(Data + len1, str, len2); Data[len1 + len2] = 0; } Length = len1 + len2; if (AutoHash) DataHash = CzString::CalculateHash(Data); return *this; }
CzString& CzString::operator+= (char chr) { int len1 = getLength(); int len2 = 1; if (Data == NULL) { allocString(len1 + len2); *Data = chr; } else { if ((len1 + len2) >= Size) reallocString(len1 + len2); *(Data + len1) = chr; Data[len1 + len2] = 0; } Length = len1 + len2; if (AutoHash) DataHash = CzString::CalculateHash(Data); return *this; }
CIwGameString& CIwGameString::operator+= (int nNum) { char str[32]; snprintf(str, 32, "%d", nNum); int len1 = GetLength(); int len2 = (int)strlen(str); if (Data == NULL) { allocString(len1 + len2); strcpy(Data, str); } else { if ((len1 + len2) >= Size) reallocString(len1 + len2); memcpy(Data + len1, str, len2); Data[len1 + len2] = 0; } Length = len1 + len2; if (AutoHash) DataHash = IwHashString(Data); return *this; }
CzString& CzString::operator+= (const char *op) { if (op == NULL) return *this; int len1 = getLength(); int len2 = (int)strlen(op); if (Data == NULL) { allocString(len1 + len2); memcpy(Data, op, len2 + 1); } else { if ((len1 + len2) >= Size) reallocString(len1 + len2); memcpy(Data + len1, op, len2); Data[len1 + len2] = 0; } Length = len1 + len2; if (AutoHash) DataHash = CzString::CalculateHash(Data); return *this; }
CIwGameString& CIwGameString::operator+= (const char *op) { if (op == NULL) return *this; int len1 = GetLength(); int len2 = (int)strlen(op); if (Data == NULL) { allocString(len1 + len2); strcpy(Data, op); } else { if ((len1 + len2) >= Size) reallocString(len1 + len2); memcpy(Data + len1, op, len2); Data[len1 + len2] = 0; } Length = len1 + len2; if (AutoHash) DataHash = IwHashString(Data); return *this; }
CIwGameString& CIwGameString::operator+= (const CIwGameString &op) { int len1 = GetLength(); int len2 = op.GetLength(); if (Data == NULL) { allocString(len1 + len2); strcpy(Data, op.c_str()); } else { if ((len1 + len2) >= Size) reallocString(len1 + len2); memcpy(Data + len1, op.c_str(), len2); Data[len1 + len2] = 0; } Length = len1 + len2; if (AutoHash) DataHash = IwHashString(Data); return *this; }
CIwGameString& CIwGameString::operator= (const char *op) { Length = (int)strlen(op); if (Data == NULL) { allocString(Length); } else { if (Length >= Size) reallocString(Length); } if (op == NULL) { Data[0] = 0; return *this; } strcpy(Data, op); if (AutoHash) DataHash = IwHashString(Data); return *this; }
char *appendString(char *s, const char *p) { int slen = strlen(s); int plen = strlen(p); s = reallocString(s, slen + plen + 1); strcpy(s + slen, p); return s; } /* appendstring */
char * newSpeak(const char * text, const char * (*replace)[2]) { TNODE * dictionary; if (NULL == (dictionary = newDictionary(replace))) return NULL; unsigned int frontIndex = 0, tailIndex = 0, translationLenght = 0, maxLenght = DEFAULT_LENGHT; const char * match; char * translation = (char *) malloc(maxLenght + 1); translation[0] = '\0'; for (frontIndex = 0; text[frontIndex] != '\0'; frontIndex++) { if (NULL != (match = findTranslation(dictionary, text + frontIndex, &tailIndex))) { frontIndex += tailIndex; translationLenght += strlen(match); while (translationLenght >= maxLenght) translation = reallocString(translation, maxLenght *= 2); strcat(translation, match); } else { if(translationLenght + 1 >= maxLenght) translation = reallocString(translation, maxLenght *= 2); translation[translationLenght++] = text[frontIndex]; translation[translationLenght] = '\0'; } } freeDictionary(dictionary); return translation; }
/* String management routines realloc to one less than a power of 2 */ void stringAndString(char **s, int *l, const char *t) { char *p = *s; int oldlen, newlen, x; oldlen = *l; newlen = oldlen + strlen(t); *l = newlen; ++newlen; /* room for the 0 */ x = oldlen ^ newlen; if (x > oldlen) { /* must realloc */ newlen |= (newlen >> 1); newlen |= (newlen >> 2); newlen |= (newlen >> 4); newlen |= (newlen >> 8); newlen |= (newlen >> 16); p = reallocString(p, newlen); *s = p; }
CIwGameString& CIwGameString::operator= (int nNum) { char str[32]; snprintf(str, 32, "%d", nNum); int len = (int)strlen(str); if (len >= Size) reallocString(len); strcpy(Data, str); Length = len; if (AutoHash) DataHash = IwHashString(Data); return *this; }
void CIwGameString::Copy(const char* pString, int start, int count) { if (Data == NULL) { allocString(count); } else { if (count >= Size) reallocString(count); } memcpy(Data, pString + start, count); Length = count; Data[count] = 0; if (AutoHash) DataHash = IwHashString(Data); }
CIwGameString& CIwGameString::operator= (const CIwGameString &op) { Length = op.GetLength(); if (Data == NULL) { allocString(Length); } else { if (Length >= Size) reallocString(Length); } if (op.c_str() == NULL) { Data[0] = 0; return *this; } strcpy(Data, op.c_str()); DataHash = op.getHash(); return *this; }