本文介绍了创建一个简单的解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

我必须开发一个简单的解析器,以读取文本的块"
例如:

Hi.

I have to develop a simple parser, to read "block" of text
for example:

/TEST
 {. text .}
/TEST_DATA
 {. infs .}



而且,我需要阅读标签内部的信息....
和...具有此信息的文件...具有很多标签,具有相同的perfil

例如:



and, I need to read informations of inside of label....
and... the file with have this informations... have a lot of labels, with the same perfil

for example:

/TEST
 {. text .}
/TEST_DATA
 {. infs .}

/LBL1
 {. text .}
/LBL1_DATA
 {. infs .}

/LBL2
 {. text .}
/LBL2_DATA
 {. infs .}

/LBL3
 {. text .}
/LBL3_DATA
 {. infs .}




我需要阅读特殊标签块,例如:

parseFile("FileName.txt",LBL1)

以及函数,为我返回块内部的文本:LBL1和LBL1_DATA
或者,为我返回LBL1和LBL1_DATA的内容

谢谢.




i need to read the block of specif label, for example:

parseFile("FileName.txt", LBL1)

and the function, return for me, the text of inside the blocks: LBL1 and LBL1_DATA
or, return for me, the content of LBL1 and LBL1_DATA

Thanks.

推荐答案


typedef struct
{
  char* text;
  void* data;
}DATA_INFO;

DATA_INFO& parseFile("FileName.txt", char* label )
{
  char* currentline;
  Openfile;
  getline( currentline );
  remove / from currentline; 
  comparestring( label, currentline );
  {
    DATA_INFO structinfo;
    structinfo.text = read text;
    skip line;
    structinfo.data = read data;
    return structinfo;
  } 
};



并澄清您有疑问的地方.



And clarify where you have doubt.


这篇关于创建一个简单的解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 17:03