1999-08-16 21:50:52 +00:00
|
|
|
/*
|
2000-01-13 23:54:23 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997-1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File CSTRING.C
|
|
|
|
*
|
|
|
|
* @author Helena Shih
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 6/18/98 hshih Created
|
1999-11-16 01:05:10 +00:00
|
|
|
* 09/08/98 stephen Added include for ctype, for Mac Port
|
|
|
|
* 11/15/99 helena Integrated S/390 IEEE changes.
|
1999-08-16 21:50:52 +00:00
|
|
|
*****************************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/putil.h"
|
1999-11-23 22:52:17 +00:00
|
|
|
#include "cstring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
char*
|
|
|
|
T_CString_toLowerCase(char* str)
|
|
|
|
{
|
|
|
|
uint32_t i=0;
|
|
|
|
while(str[i])
|
|
|
|
str[i++] = tolower(str[i]);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
T_CString_toUpperCase(char* str)
|
|
|
|
{
|
|
|
|
uint32_t i=0;
|
|
|
|
while(str[i])
|
|
|
|
str[i++] = toupper(str[i]);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Takes a int32_t and fills in a char* string with that number "radix"-based*/
|
|
|
|
|
|
|
|
void T_CString_integerToString(char* buffer, int32_t i, int32_t radix)
|
|
|
|
{
|
|
|
|
int32_t length=0;
|
|
|
|
int32_t num = 0;
|
|
|
|
int8_t digit;
|
|
|
|
char temp;
|
|
|
|
|
2000-04-07 16:58:58 +00:00
|
|
|
while (i>=radix)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
num = i/radix;
|
|
|
|
digit = (int8_t)(i - num*radix);
|
|
|
|
buffer[length++] = (T_CString_itosOffset(digit));
|
|
|
|
i = num;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[length] = (T_CString_itosOffset(i));
|
|
|
|
buffer[length+1] = '\0';
|
|
|
|
|
|
|
|
|
|
|
|
/*Reverses the string*/
|
2000-04-07 16:58:58 +00:00
|
|
|
for (i = 0; i < length; ++i, --length) {
|
|
|
|
temp = buffer[length];
|
|
|
|
buffer[length] = buffer[i];
|
|
|
|
buffer[i] = temp;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
T_CString_stringToInteger(const char *integerString, int32_t radix)
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
return strtoul(integerString, &end, radix);
|
1999-11-16 01:05:10 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-11-23 22:52:17 +00:00
|
|
|
U_CAPI int U_EXPORT2
|
|
|
|
T_CString_stricmp(const char *str1, const char *str2) {
|
|
|
|
if(str1==NULL) {
|
|
|
|
if(str2==NULL) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else if(str2==NULL) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
/* compare non-NULL strings lexically with lowercase */
|
|
|
|
int rc;
|
|
|
|
unsigned char c1, c2;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-11-23 22:52:17 +00:00
|
|
|
for(;;) {
|
|
|
|
c1=(unsigned char)*str1;
|
|
|
|
c2=(unsigned char)*str2;
|
|
|
|
if(c1==0) {
|
|
|
|
if(c2==0) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else if(c2==0) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
/* compare non-zero characters with lowercase */
|
1999-12-28 23:39:02 +00:00
|
|
|
rc=(int)(unsigned char)uprv_tolower(c1)-(int)(unsigned char)uprv_tolower(c2);
|
1999-11-23 22:52:17 +00:00
|
|
|
if(rc!=0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++str1;
|
|
|
|
++str2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-06 23:06:48 +00:00
|
|
|
|
|
|
|
#if !U_HAVE_WCHAR_H
|
|
|
|
U_CAPI wchar_t *uprv_wcscat(wchar_t *dst, const wchar_t *src) {
|
|
|
|
wchar_t *start=dst;
|
|
|
|
while(*dst!=0) {
|
|
|
|
++dst;
|
|
|
|
}
|
|
|
|
while((*dst=*src)!=0) {
|
|
|
|
++dst;
|
|
|
|
++src;
|
|
|
|
}
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI wchar_t *uprv_wcscpy(wchar_t *dst, const wchar_t *src) {
|
|
|
|
wchar_t *start=dst;
|
|
|
|
while((*dst=*src)!=0) {
|
|
|
|
++dst;
|
|
|
|
++src;
|
|
|
|
}
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI size_t uprv_wcslen(const wchar_t *src) {
|
|
|
|
const wchar_t *start=src;
|
|
|
|
while(*src!=0) {
|
|
|
|
++src;
|
|
|
|
}
|
|
|
|
return src-start;
|
|
|
|
}
|
|
|
|
#endif
|