示例#1
0
  virtual void OnScalar(const Mark&, const std::string& tag, anchor_t anch,
                        const std::string& str) {
      std::cout << "=VAL";
      if (anch > 0) {
        std::cout << " &" << anch;
      }
      if (tag.compare("?") && tag.compare("!")) {
        std::cout << " <" << tag << ">";
      }
      std::string val = (std::string)str;

      myReplace(val, "\\", "\\\\");
      myReplace(val, "\t", "\\t");
      myReplace(val, "\b", "\\b");
      myReplace(val, "\n", "\\n");
      myReplace(val, "\r", "\\r");
      std::cout << " :" << val << "\n";
  }
void PanelCode::selfSetup(){
	
	string codeFile = dataPath + "code_test.txt";
	if(ofFile(codeFile).exists()){
		initialBuffer = ofBufferFromFile(codeFile);
		while(!initialBuffer.isLastLine()){
			string line = initialBuffer.getNextLine();
			myReplace(line, "\n", "\\n");
//			myReplace(line, "\"", "\\\"");
//			myReplace(line, "\t", "\\t");			
			lines.push_back(line);
		}
		
		offset = ofRandom(lines.size() - 40);
		
		ofxRegex r;
		int startIndex;
		int matchLen;
		int lastIndex;
		for(int lI = 0; lI < lines.size(); lI++){
			
			SyntaxLine sL;
			//for each line
			string line = lines[lI];
			//calculate char counts
			for(int i = 0; i < line.size(); i++){
				sL.charCounts[ line.at(i) ]++;
			}
			
			map<unsigned char,int>::iterator it;
			for(it = sL.charCounts.begin(); it != sL.charCounts.end(); it++){
				maxCharsOnLine = MAX(maxCharsOnLine,it->second);
			}
			
			for(int mI = 0; mI < MATCH_TYPES; mI++){
				
				vector<string> matched = r.getMatchedStrings(line, toMatch[mI]);
				
				//reset the "search from" index
				lastIndex = 0;
				string cLine = "";
				
				for (vector<string>::iterator it = matched.begin(); it != matched.end(); ++it){
					//for each match
					//find where the match is in the rest of the current line
					startIndex = indexOf(line, *it, lastIndex);
					if (startIndex < 0){
						cout<<"BIG PROBLEM"<<endl;
					}
					
					//in the colored output, insert spaces between last match and current match
					for(int i = lastIndex; i < startIndex; i++){
						cLine += " ";
					}
					matchLen = it->length();
					//move the matched text to the colored output
					//and replace it with spaces in the source
					for(int i = 0; i < matchLen; i++){
						cLine += line[startIndex+i];
						line.replace(startIndex + i, 1, " ");
					}
					lastIndex = startIndex + matchLen;
				}
				sL.colored[mI] += cLine;
			}
			sL.baseLine = line;
			syntaxLines.push_back(sL);
		}
	}
	
	maxCharsOnLine = 0;
}
void Bank::Parse(string bank)
{
	size_t sectionStart = 0;
	size_t sectionEnd = 0;
	size_t keyStart = 0;
	size_t keyEnd = 0;
	size_t keyValueNameStart = 0;
	size_t keyValueTypeStart = 0;
	size_t keyValueStart = 0;
	size_t sigStart = 0;
	string sectionName;
	string keyName;
	string keyValueName;
	string keyValueType;
	string keyValue;
	string sig;

	KeyValue kv;

	while((sectionStart = bank.find("<Section name=\"", sectionEnd)) != string::npos)
	{
		sectionEnd = bank.find("</Section>", sectionStart);
		sectionName.clear();
		for(size_t i = sectionStart + 15; i < bank.size() && bank[i] != '\"'; i++)
			sectionName += bank[i];
		this->Sections.push_back(Section(sectionName));

		keyEnd = keyStart = sectionStart;
		while((keyStart = bank.find("<Key name=\"", keyEnd)) != string::npos && keyStart < sectionEnd)
		{
			keyEnd = bank.find("</Key>", keyStart);
			keyValueNameStart = keyStart;
			keyName.clear();
			keyValueName.clear();
			keyValueType.clear();
			keyValue.clear();
			for(size_t i = keyStart + 11; i < bank.size() && bank[i] != '\"'; i++)
				keyName += bank[i];
			this->Sections.back().Keys.push_back(Key(keyName));

			do
			{
				keyValueNameStart = bank.find("<", keyValueNameStart + 1);
				if(keyValueNameStart < keyEnd)
				{
					keyValueTypeStart = bank.find(" ", keyValueNameStart);
					keyValueStart = bank.find("=\"", keyValueNameStart);

					keyValueName.clear();
					keyValueType.clear();
					keyValue.clear();

					for(size_t i = keyValueNameStart + 1; i < bank.size() && bank[i] != ' '; i++)
						keyValueName += bank[i];

					for(size_t i = keyValueTypeStart + 1; i < bank.size() && bank[i] != '='; i++)
						keyValueType += bank[i];

					for(size_t i = keyValueStart + 2; i < bank.size() && bank[i] != '"'; i++)
						keyValue += bank[i];
					
					myReplace(keyValue, "&quot;", "\"");
					myReplace(keyValue, "&apos;", "'");
					myReplace(keyValue, "&gt;", ">");
					myReplace(keyValue, "&lt;", "<");
					myReplace(keyValue, "&amp;", "&");

					kv.ValueName = keyValueName;
					kv.ValueType = keyValueType;
					kv.Value = keyValue;

					this->Sections.back().Keys.back().Values.push_back(kv);
				}
			} while(keyValueNameStart < keyEnd);
		}
	}

	sigStart = bank.find("<Signature value=\"");
	if(sigStart != string::npos)
	{
		for(size_t i = sigStart + 18; i < bank.size() && bank[i] != '"'; i++)
			sig += bank[i];
		this->Signature = sig;
	}
}