//-----------------------------------------------------------------------------+ // 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; }