Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

130 lines
2.0 KiB
C++

//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, SH Software Co. Ltd.
// = FileName : XAStringList.cpp
// = Version : ver2.0
// = Author : zjq
// = CreateDate : 2002-09-09
// = Description: 类的定义
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "XAStringList.h"
#include "XGlobalFunc.h"
XAStringList::XAStringList(const char **pBeg, int nCount)
{
m_nDelFlag = 1;
const char **p = pBeg;
for (int i = 0; i < nCount; i++)
{
Append(strnew(*p));
p++;
}
}
XAStringList::XAStringList()
{
}
XAStringList::XAStringList(XAStringList &src)
{
*this = src;
}
XAStringList::~XAStringList()
{
}
// 返回符号表的序号: -1表示符号不在列表里
// 不分大小写
int XAStringList::Index(const char *sym, int caseSense)
{
if (!sym)
{
return -1;
}
int len = Length();
if (!caseSense)
{
for (int i = 0; i < len; i++)
{
if (_stricmp((*this)[i], sym) == 0)
{
return i;
}
}
}
else
{
for(int i = 0; i < len; i++)
{
if (strcmp((*this)[i], sym) == 0)
{
return i;
}
}
}
return -1;
}
XAStringList & XAStringList::operator =(XAStringList &src)
{
Reset();
int len = src.Length();
for (int i = 0; i < len; i++)
{
Append(strnew(src[i]));
}
return *this;
}
typedef int (* StrCompFun)(const char *, const char *);
char * XAStringList::MaxValue(int caseSence)
{
StrCompFun cmp = caseSence ? strcmp : _stricmp;
int len = Length();
char *res = NULL;
for (int i = 0; i < len; i++)
{
if (!res)
{
res = (*this)[i];
}
else
{
res = cmp(res,(*this)[i]) >= 0 ? res : (*this)[i];
}
}
return res;
}
char * XAStringList::MinValue(int caseSence)
{
StrCompFun cmp = caseSence ? strcmp : _stricmp;
int len = Length();
char *res = NULL;
for (int i = 0; i < len; i++)
{
if (!res)
{
res = (*this)[i];
}
else
{
res = cmp(res,(*this)[i]) <= 0 ? res : (*this)[i];
}
}
return res;
}