📄 textrow.cpp
字号:
/*Function : TextRow Class uses to process one text row,analyze every atom
*Author : Liu Zhong
*Copyright: Commercial, Copyright@2002 by Liu Zhong
*BeginDate: 2002.10.21
*ChangeLog: 2002.10.21
*/
#include "textrow.h"
TextRow::TextRow(char* Row,char* FindMark)
{
SetRow(Row,FindMark);
}
TextRow::TextRow(TextRow& Row)
{
*this = Row;
}
TextRow::~TextRow()
{
}
void TextRow::DoAnalyse()
{
m_Count = 0;
for(int i=0;i<MaxFieldNum;i++) m_Fields[i] = NULL;
if(strlen(m_Row)>0 && strlen(m_FindMark)>0){
char** pField = m_Fields;
char* UsePtr=NULL;
*pField = strtok_r(m_Row,m_FindMark,&UsePtr);
while(*pField!=NULL){
if(m_Count<MaxFieldNum){
m_Count++;
*pField++;
}
*pField = strtok_r(NULL,m_FindMark,&UsePtr);
};
}
}
void TextRow::SetRow(char* Row,char* FindMark)
{
if(Row) strcpy(m_Row,Row);
else memset(m_Row,0,MaxRowLen);
if(FindMark) strcpy(m_FindMark,FindMark);
else memset(m_FindMark,0,MaxMarkLen);
DoAnalyse();
}
string TextRow::GetRow()
{
char Row[MaxRowLen];
memset(Row,0,MaxRowLen);
for(int i=0;i<Count();i++){
strcat(Row,m_Fields[i]);
if(i<Count()-1) strcat(Row,m_FindMark);
}
return Row;
}
int TextRow::Count()
{
return m_Count;
}
char* TextRow::Fields(int Index)
{
if(Index>=0 && Index<m_Count){
return m_Fields[Index];
}
else{
return NULL;
}
}
int TextRow::ToInt(int Index)
{
int Val = 0;
if(Index>=0 && Index<m_Count){
Val = atoi(m_Fields[Index]);
}
return Val;
}
double TextRow::ToDouble(int Index)
{
double Val = 0;
if(Index>=0 && Index<m_Count){
Val = atof(m_Fields[Index]);
}
return Val;
}
void TextRow::AddField(char* Field)
{
char Row[MaxRowLen];
memset(Row,0,MaxRowLen);
for(int i=0;i<m_Count;i++){
strcat(Row,m_Fields[i]);
if(i<m_Count-1) strcat(Row,m_FindMark);
}
memcpy(m_Row,Row,MaxRowLen);
if(m_Count>0){
strcat(m_Row,m_FindMark);
}
strcat(m_Row,Field);
DoAnalyse();
}
void TextRow::DeleteField(int FldNo)
{
if(m_Count>0 && FldNo<m_Count){
char Row[MaxRowLen];
memset(Row,0,MaxRowLen);
for(int i=0;i<FldNo;i++){
strcat(Row,m_Fields[i]);
if(i!=FldNo-1&&FldNo+1!=m_Count){
strcat(Row,m_FindMark);
}
}
for(int i=FldNo+1;i++;i<m_Count){
strcat(Row,m_Fields[i]);
if(i<m_Count-1) strcat(Row,m_FindMark);
}
memcpy(m_Row,Row,MaxRowLen);
DoAnalyse();
}
}
void TextRow::InsertBefore(int FldNo,char* Field)
{
if(FldNo>=0 && FldNo<=m_Count){
char Row[MaxRowLen];
memset(Row,0,MaxRowLen);
for(int i=0;i<FldNo;i++){
strcat(Row,m_Fields[i]);
if(i!=FldNo-1&&FldNo+1!=m_Count){
strcat(Row,m_FindMark);
}
}
strcat(Row,Field);
if(FldNo<m_Count){
strcat(Row,m_FindMark);
for(int i=FldNo;i++;i<m_Count){
strcat(Row,m_Fields[i]);
if(i<m_Count-1) strcat(Row,m_FindMark);
}
}
memcpy(m_Row,Row,MaxRowLen);
DoAnalyse();
}
}
TextRow& TextRow::operator=(TextRow& Row)
{
memcpy(m_Row,Row.m_Row,MaxRowLen);
memcpy(m_FindMark,Row.m_FindMark,MaxMarkLen);
DoAnalyse();
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -