119 lines
1.7 KiB
C++
119 lines
1.7 KiB
C++
#include "StdAfx.h"
|
|
#include "ACStringList.h"
|
|
#include "globalfunc.h"
|
|
|
|
ACStringList::ACStringList(const char **pBeg, int nCount)
|
|
{
|
|
m_nDelFlag = 1;
|
|
const char **p = pBeg;
|
|
|
|
for (int i = 0; i < nCount; i++)
|
|
{
|
|
Append(GlobalFunc::StrNew(*p));
|
|
p++;
|
|
}
|
|
}
|
|
|
|
ACStringList::ACStringList()
|
|
{
|
|
|
|
}
|
|
|
|
ACStringList::ACStringList(ACStringList &src)
|
|
{
|
|
*this = src;
|
|
}
|
|
|
|
ACStringList::~ACStringList()
|
|
{
|
|
|
|
}
|
|
|
|
// 返回符号表的序号: -1表示符号不在列表里
|
|
// 不分大小写
|
|
int ACStringList::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;
|
|
}
|
|
|
|
ACStringList & ACStringList::operator =(ACStringList &src)
|
|
{
|
|
Reset();
|
|
|
|
int len = src.Length();
|
|
for (int i = 0; i < len; i++)
|
|
{
|
|
Append(GlobalFunc::StrNew(src[i]));
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
typedef int (* StrCompFun)(const char *, const char *);
|
|
char * ACStringList::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 * ACStringList::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;
|
|
} |