129 lines
2.0 KiB
C++
129 lines
2.0 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TACStringList.cpp
|
|
// = Version : ver2.0
|
|
// = Author : xlc
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: 类的定义
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TACStringList.h"
|
|
#include "TchGlobalFunc.h"
|
|
|
|
TACStringList::TACStringList(const char **pBeg, int nCount)
|
|
{
|
|
m_nDelFlag = 1;
|
|
const char **p = pBeg;
|
|
|
|
for (int i = 0; i < nCount; i++)
|
|
{
|
|
Append(StrNew(*p));
|
|
p++;
|
|
}
|
|
}
|
|
|
|
TACStringList::TACStringList()
|
|
{
|
|
|
|
}
|
|
|
|
TACStringList::TACStringList(TACStringList &src)
|
|
{
|
|
*this = src;
|
|
}
|
|
|
|
TACStringList::~TACStringList()
|
|
{
|
|
|
|
}
|
|
|
|
// 返回符号表的序号: -1表示符号不在列表里
|
|
// 不分大小写
|
|
int TACStringList::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;
|
|
}
|
|
|
|
TACStringList & TACStringList::operator =(TACStringList &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 * TACStringList::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 * TACStringList::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;
|
|
} |