namespace commonUtil
{
StrUtil::StrUtil()
{
}
StrUtil::~StrUtil()
{
}
int StrUtil::GetSizeOfStr(
const
char * str_input)
{
if ((
NULL == str_input))
{
return
0;
}
char *tmp =
const_cast<
char*>(str_input);
int length =
0;
while (
'\0' != *tmp)
{
++length;
tmp++;
}
return length;
}
int StrUtil::StrToUpper(
const
char * str_input,
char *str_output)
{
if ((
NULL == str_input) || (
NULL == str_output))
{
return -
1;
}
char * tmp_output = str_output;
char * tmp_input =
const_cast<
char*>(str_input);
while (*tmp_input !=
'\0')
{
if (*tmp_input <=
'z' && *tmp_input >=
'a')
{
*tmp_output = *tmp_input -
32;
}
else
{
*tmp_output = *tmp_input;
}
++tmp_output;
++tmp_input;
}
*tmp_output =
'\0';
return
0;
}
int StrUtil::StrToLower(
const
char * str_input,
char *str_output)
{
if ((
NULL == str_input) || (
NULL == str_output))
{
return -
1;
}
char* tmp_input =
const_cast<
char*>(str_input);
char * tmp_output = str_output;
while (*tmp_input !=
'\0')
{
if (*tmp_input <=
'Z' && *tmp_input >=
'A')
{
*tmp_output = *tmp_input +
32;
}
else
{
*tmp_output = *tmp_input;
}
++tmp_output;
++tmp_input;
}
*tmp_output =
'\0';
return
0;
}
int StrUtil::StrCat(
char *ori_input,
const
char *cat_str)
{
if (
NULL == ori_input)
{
return -
1;
}
char *tmp1 = ori_input;
char *tmp2 =
const_cast<
char*>(cat_str);
tmp1 = tmp1 + GetSizeOfStr(ori_input);
while (
'\0' != *tmp2)
{
*tmp1 = *tmp2;
++tmp1;
++tmp2;
}
*tmp1 =
'\0';
return
0;
}
}