📄 index.cpp
字号:
// INDEX.cpp: implementation of the INDEX class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CREATOR.h"
#include "INDEX.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#include "Line.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
INDEX::INDEX()
{sum=0;
string=string+"}"+' ';
for(int i=0;i<26;i++)
{index[i]=0;indexword[i]=0;}
}
INDEX::~INDEX()
{
}
CString INDEX::GetIndexFirstword(char ch)
{CLine newcline(string);
return newcline.DrawWord(indexword[toupper(ch-'A')]+1);
}
void INDEX::AddIndex( CString word)
{ CString temp;
char ch=word.GetAt(0);
int nowindex=0,i,j=0;//j是循环变量
i=toupper(ch)-'A';
sum++;
if(indexword[i]==0) indexword[i]++;//如果是第一次给这个字符入index,那么indexword就加一
nowindex=index[i];
while(1)
{ temp=Getword(nowindex);
if(temp.Compare(word)>0)
{ Insertstring(nowindex,word);
break;}//插入word && break;
else if (temp.Compare(word)==0) Sleep(1);//报错
else
while(string.GetAt(nowindex++)!=' ');//后移
}
for(j=i+1;j<=25;j++)
{index[j]+=word.GetLength()+1;
indexword[j]++;
}
}
void INDEX::Insertstring(int index, CString insertstring)//index 是下标,insertstring是插入的字符串
{ CString front,back;
front=string.Left(index);
back=string.Mid(index);
string=front+insertstring+" "+back;
}
void INDEX::Insertsubstring(int nowindex, CString sData)
{CString front,back;
front=string.Left(nowindex);
back=string.Mid(nowindex);
string=front+sData+" "+back;
}
CString INDEX::Getword(int address)
{CString temp;
char ch;
while(1)
{ch=string.GetAt(address++);
if(ch==' '||ch==','||ch==':') break;
else temp+=ch;
}
return temp;
}
CString INDEX::Getword(CString outstring,int address)
{CString temp;
char ch;
while(1)
{ch=outstring.GetAt(address++);
if(ch==' '||ch==','||ch==':') break;
else temp+=ch;
}
return temp;
}
CString INDEX::Getstring()
{
return string.Left(string.GetLength()-2);
}
CString INDEX::GetData(int address)
{CString temp;
BOOL flag=FALSE;
char ch;
while(1)
{ch=string.GetAt(address++);
if(ch==':') flag=TRUE;
if(flag)
if(ch==' '||ch==',') break;
else temp+=ch;
}
return temp;
}
CString INDEX::FindData(CString word)//找到word对应的数据的字符串
{BOOL flag=FALSE;
int i=0;
i=index[word.GetAt(0)];
for(;i<string.GetLength();i++)
{if(Getword(i)==word) {flag=TRUE;break;}
else while(string.GetAt(++i)==' ');//跳到下一个空格
}
if (!flag) return "没找到";//没找到返回特殊字符串
return GetData(i);
}
CString INDEX::IndexWork(CString word)//返回word 对应的Data
{CString mystring;
CLine myLine;
myLine.InputLine(string);
int j=0,k=0,l=0;
j=toupper(word.GetAt(0))-'A';
for(int i=indexword[j];i<=indexword[j+1];i++)
//从word第一个字符对应的坐标,结束于word第一个字符的下一字符对应的坐标
{if((mystring=myLine.DrawWord(2*i-1))==word) return myLine.DrawWordX(2*i);}
return word;
}
CString INDEX::Takeword(CString string,int address)//抽取不算‘:’的单词
{return "";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -