Esempio n. 1
0
CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place,
                                             const FX_WCHAR* text) {
  CFX_WideString swText = text;
  CPVT_WordPlace wp = place;
  for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) {
    CPVT_WordPlace oldwp = wp;
    uint16_t word = swText.GetAt(i);
    switch (word) {
      case 0x0D:
        if (m_bMultiLine) {
          if (swText.GetAt(i + 1) == 0x0A)
            i += 1;

          wp = InsertSection(wp, nullptr, nullptr);
        }
        break;
      case 0x0A:
        if (m_bMultiLine) {
          if (swText.GetAt(i + 1) == 0x0D)
            i += 1;

          wp = InsertSection(wp, nullptr, nullptr);
        }
        break;
      case 0x09:
        word = 0x20;
      default:
        wp = InsertWord(wp, word, FXFONT_DEFAULT_CHARSET, nullptr);
        break;
    }
    if (wp == oldwp)
      break;
  }
  return wp;
}
INIFile::Section* INIFile::getSectionOrCreate(const std::string& sectionname) {
	Section* curSection = getSection(sectionname);

	if(curSection == NULL) {
		// create new section

		if(isValidSectionName(sectionname) == false) {
			std::cerr << "INIFile: Cannot create section with name " << sectionname << "!" << std::endl;
			return NULL;
		}

		curSection = new Section(sectionname);

		if(FirstLine == NULL) {
			FirstLine = curSection;
		} else {
            INIFileLine* curLine = FirstLine;
			while(curLine->nextLine != NULL) {
				curLine = curLine->nextLine;
			}

			curLine->nextLine = curSection;
			curSection->prevLine = curLine;
		}

		InsertSection(curSection);
	}
    return curSection;
}
Esempio n. 3
0
bool CSongState::EditSectionProperties(int Beat)
{
	int	iSection = m_Section.FindBeat(Beat);
	// if section not found, or section is implicit
	if (iSection < 0 || m_Section[iSection].Implicit())
		return(FALSE);
	CSong::CSection	sec(m_Section[iSection]);
	CString	name(m_SectionName[iSection]);
	CSectionPropsDlg	dlg(sec, name);
	if (dlg.DoModal() != IDOK)
		return(FALSE);
	// if section start or length changed
	if (sec.m_Start != m_Section[iSection].m_Start
	|| sec.m_Length != m_Section[iSection].m_Length) {
		if (!DeleteSection(Beat))	// delete section
			return(FALSE);
		MakeSectionMap();	// rebuild section map before inserting
		if (!InsertSection(sec, name))	// reinsert section
			return(FALSE);
	} else {	// start and length unchanged
		m_Section[iSection] = sec;
		m_SectionName[iSection] = name;
	}
	return(TRUE);
}
void INIFile::readfile(SDL_RWops * file)
{
	SectionRoot = new Section("",0,0);

	Section* curSection = SectionRoot;

	std::string completeLine;
	int lineNum = 0;
	bool SyntaxError = false;
	INIFileLine* curLine = NULL;
	INIFileLine* newINIFileLine;
	Section* newSection;
	Key* newKey;

	bool readfinished = false;

	while(!readfinished) {
		lineNum++;

		completeLine = "";
		unsigned char tmp;
		int readbytes;

		while(1) {
			readbytes = SDL_RWread(file,&tmp,1,1);
			if(readbytes <= 0) {
				readfinished = true;
				break;
			} else if(tmp == '\n') {
				break;
			} else if(tmp != '\r') {
				completeLine += tmp;
			}
		}

		const unsigned char* line = (const unsigned char*) completeLine.c_str();
		SyntaxError = false;
		int ret;

		ret = getNextChar(line,0);

		if(ret == -1) {
			// empty line or comment
			newINIFileLine = new INIFileLine(completeLine);

			if(curLine == NULL) {
				FirstLine = newINIFileLine;
				curLine = newINIFileLine;
			} else {
				curLine->nextLine = newINIFileLine;
				newINIFileLine->prevLine = curLine;
				curLine = newINIFileLine;
			}
		} else {

			if(line[ret] == '[') {
				// section line
				int sectionstart = ret+1;
				int sectionend = skipName(line,ret+1);

				if((line[sectionend] != ']') ||	(getNextChar(line,sectionend+1) != -1)) {
					SyntaxError = true;
				} else {
					// valid section line
					newSection = new Section(completeLine,sectionstart,sectionend-sectionstart);

					if(curLine == NULL) {
						FirstLine = newSection;
						curLine = newSection;
					} else {
						curLine->nextLine = newSection;
						newSection->prevLine = curLine;
						curLine = newSection;
					}

					InsertSection(newSection);
					curSection = newSection;
				}
			} else {

				// might be key/value line
				int keystart = ret;
				int keyend = skipKey(line,keystart);

				if(keystart == keyend) {
					SyntaxError = true;
				} else {
					ret = getNextChar(line,keyend);
					if((ret == -1) ||(line[ret] != '=')) {
						SyntaxError = true;
					} else {
						int valuestart = getNextChar(line,ret+1);
						if(valuestart == -1) {
							SyntaxError = true;
						} else {
							if(line[valuestart] == '"') {
								// now get the next '"'

								int valueend = getNextQuote(line,valuestart+1);

								if((valueend == -1) || (getNextChar(line,valueend+1) != -1)) {
									SyntaxError = true;
								} else {
									// valid key/value line
									newKey = new Key(completeLine,keystart,keyend-keystart,valuestart+1,valueend-valuestart-1);

									if(FirstLine == NULL) {
										FirstLine = newKey;
										curLine = newKey;
									} else {
										curLine->nextLine = newKey;
										newKey->prevLine = curLine;
										curLine = newKey;
									}

									curSection->InsertKey(newKey);
								}

							} else {
								int valueend = skipValue(line,valuestart);

								if(getNextChar(line,valueend) != -1) {
									SyntaxError = true;
								} else {
									// valid key/value line
									newKey = new Key(completeLine,keystart,keyend-keystart,valuestart,valueend-valuestart);

									if(FirstLine == NULL) {
										FirstLine = newKey;
										curLine = newKey;
									} else {
										curLine->nextLine = newKey;
										newKey->prevLine = curLine;
										curLine = newKey;
									}

									curSection->InsertKey(newKey);
								}
							}
						}
					}
				}

			}
		}

		if(SyntaxError == true) {
			if(completeLine.size() < 100) {
				// there are some buggy ini-files which have a lot of waste at the end of the file
				// and it makes no sense to print all this stuff out. just skip it
				std::cerr << "INIFile: Syntax-Error in line " << lineNum << ":" << completeLine << " !" << std::endl;
			}
			// save this line as a comment
			newINIFileLine = new INIFileLine(completeLine);

			if(curLine == NULL) {
				FirstLine = newINIFileLine;
				curLine = newINIFileLine;
			} else {
				curLine->nextLine = newINIFileLine;
				newINIFileLine->prevLine = curLine;
				curLine = newINIFileLine;
			}
		}



	}
}
Esempio n. 5
0
void CSongState::CreateSection(CIntRange BeatRange)
{
	CSong::CSection	sec(BeatRange.Start, BeatRange.LengthInclusive(), 0);
	InsertSection(sec, _T(""));
}
Esempio n. 6
0
void IniFile::readFile()
{	
	if((SectionRoot = new SectionEntry("",0,0)) == nullptr)
    	    throw(std::bad_alloc());
	
	SectionEntry *curSectionEntry = SectionRoot;
		
	std::string completeLine;
	int lineNum = 0;
	bool SyntaxError = false;
	CommentEntry *curEntry = nullptr;
	CommentEntry *newCommentEntry;
	SectionEntry *newSectionEntry;
	KeyEntry *newKeyEntry;
	
	bool readfinished = false;
	
	while(!readfinished) {
		lineNum++;
		
		completeLine = "";
		uint8_t tmp;
		
		size_t size = _stream.sizeg();
		while(static_cast<uint32_t>(_stream.tellg()) < size-1) {
			tmp = _stream.get();
			if(static_cast<uint32_t>(_stream.tellg()) == size-1) {
				readfinished = true;
				break;
			} else if(tmp == '\n') {
				break;
			} else if(tmp != '\r') {
				completeLine += tmp;
			}
		}
		
		const uint8_t *line = reinterpret_cast<const uint8_t*>(completeLine.c_str());
		SyntaxError = false;
		int ret;

		ret = getNextChar(line,0);
		
		if(ret == -1) {
			// empty line or comment
			if((newCommentEntry = new CommentEntry(completeLine)) == nullptr)
		    	    throw(std::bad_alloc());
			
			if(curEntry == nullptr) {
				FirstLine = newCommentEntry;
				curEntry = newCommentEntry;
			} else {
				curEntry->nextEntry = newCommentEntry;
				newCommentEntry->prevEntry = curEntry;
				curEntry = newCommentEntry;
			}
		} else {
		
			if(line[ret] == '[') {
				// section line
				int sectionstart = ret+1;
				int sectionend = skipName(line,ret+1);
			
				if((line[sectionend] != ']') ||	(getNextChar(line,sectionend+1) != -1)) {
					SyntaxError = true;
				} else {
					// valid section line
					if((newSectionEntry = new SectionEntry(completeLine,sectionstart,sectionend-sectionstart)) == nullptr)
				    	    throw(std::bad_alloc());
			
					if(curEntry == nullptr) {
						FirstLine = newSectionEntry;
						curEntry = newSectionEntry;
					} else {
						curEntry->nextEntry = newSectionEntry;
						newSectionEntry->prevEntry = curEntry;
						curEntry = newSectionEntry;
					}
					
					InsertSection(newSectionEntry);
					curSectionEntry = newSectionEntry;
				}
			} else {
			
				// might be key/value line
				int keystart = ret;
				int keyend = skipKey(line,keystart);
				
				if(keystart == keyend) {
					SyntaxError = true;
				} else {
					ret = getNextChar(line,keyend);
					if((ret == -1) ||(line[ret] != '=')) {
						SyntaxError = true;
					} else {
						int valuestart = getNextChar(line,ret+1);
						int valueend;
						if(valuestart == -1) {
							SyntaxError = true;
						} else {
							if(line[valuestart] == '"') {
								// now get the next '"'
								
								valueend = getNextQuote(line,valuestart+1);
								
								if((valueend == -1) || (getNextChar(line,valueend+1) != -1)) {
									SyntaxError = true;
								} else {
									// valid key/value line
									if((newKeyEntry = new KeyEntry(completeLine,keystart,keyend-keystart,valuestart+1,valueend-valuestart-1)) == nullptr)
								    	    throw(std::bad_alloc());

									if(FirstLine == nullptr) {
										FirstLine = newKeyEntry;
										curEntry = newKeyEntry;
									} else {
										curEntry->nextEntry = newKeyEntry;
										newKeyEntry->prevEntry = curEntry;
										curEntry = newKeyEntry;
									}
					
									InsertKey(curSectionEntry,newKeyEntry);										
								}
								
							} else {
								valueend = skipValue(line,valuestart);
								
								if(getNextChar(line,valueend) != -1) {
									SyntaxError = true;
								} else {
									// valid key/value line
									if((newKeyEntry = new KeyEntry(completeLine,keystart,keyend-keystart,valuestart,valueend-valuestart)) == nullptr)
								    	    throw(std::bad_alloc());


									if(FirstLine == nullptr) {
										FirstLine = newKeyEntry;
										curEntry = newKeyEntry;
									} else {
										curEntry->nextEntry = newKeyEntry;
										newKeyEntry->prevEntry = curEntry;
										curEntry = newKeyEntry;
									}
					
									InsertKey(curSectionEntry,newKeyEntry);									
								}
							}
						}
					}
				}
				
			}
		}
		
		if(SyntaxError == true) {
			if(completeLine.size() < 100) {
				// there are some buggy ini-files which have a lot of waste at the end of the file
				// and it makes no sense to print all this stuff out. just skip it
			    std::cerr << "IniFile: Syntax-Error in line " << lineNum << ":" << completeLine << " !" << std::endl;
			}
			// save this line as a comment
			if((newCommentEntry = new CommentEntry(completeLine)) == nullptr)
		    	    throw(std::bad_alloc());
			
			if(curEntry == nullptr) {
				FirstLine = newCommentEntry;
				curEntry = newCommentEntry;
			} else {
				curEntry->nextEntry = newCommentEntry;
				newCommentEntry->prevEntry = curEntry;
				curEntry = newCommentEntry;
			}		
		}
		
		
		
	}
}
Esempio n. 7
0
/**
	Sets the std::string that is adressed by the section/key pair to value. If the section and/or the key does not exist it will
	be created. A valid sectionname/keyname is not allowed to contain '[',']',';' or '#' and can not start or end with
	whitespaces (' ' or '\\t').
	\param	section			sectionname
	\param	key				keyname
	\param	value			value that should be set
*/
void IniFile::setStringValue(std::string section, std::string key, std::string value)
{
	CommentEntry *curEntry = nullptr;
	SectionEntry *curSection = getSection(section);
	
	if(curSection == nullptr) {
		// create new section
		
		// test for valid section name
		bool NonNormalCharFound = false;
		for(unsigned int i = 0; i < section.size(); i++) {
			if( (!isNormalChar(section[i])) && (!isWhitespace(section[i])) ) {
				NonNormalCharFound = true;
			}
		}
		
		if(isWhitespace(section[0]) || isWhitespace(section[section.size()-1])) {
			NonNormalCharFound = true;
		}
		
		if(NonNormalCharFound == true) {
		    std::cerr << "IniFile: Cannot create section with name " << section << "!" << std::endl;
			return;
		}
		
		std::string completeLine = "[" + section + "]";
		if((curSection = new SectionEntry(completeLine,1,section.size())) == nullptr)
	    	    throw(std::bad_alloc());

		if(FirstLine == nullptr) {
			FirstLine = curSection;
		} else {
			curEntry = FirstLine;
			while(curEntry->nextEntry != nullptr) {
				curEntry = curEntry->nextEntry;
			}
			
			curEntry->nextEntry = curSection;
			curSection->prevEntry = curEntry;
			curEntry = curSection;
		}
					
		InsertSection(curSection);
	}
	
	KeyEntry *curKey = getKey(curSection,key);
	if(curKey == nullptr) {
		// create new key
		
		// test for valid key name
		bool NonNormalCharFound = false;
		for(unsigned int i = 0; i < key.size(); i++) {
			if( (!isNormalChar(key[i])) && (!isWhitespace(key[i])) ) {
				NonNormalCharFound = true;
			}
		}
		
		if(isWhitespace(key[0]) || isWhitespace(key[key.size()-1])) {
			NonNormalCharFound = true;
		}
		
		if(NonNormalCharFound == true) {
		    std::cerr << "IniFile: Cannot create key with name " << key << "!" << std::endl;
			return;
		}

		std::string completeLine;
		int KeyStringStart;
		int KeyStringLength;
		int ValueStringStart;
		int ValueStringLength;
		if(value == "") {
			completeLine = key + " = \"" + value + "\"" ;
			KeyStringStart = 0;
			KeyStringLength = key.size();
			ValueStringStart = key.size()+4;
			ValueStringLength = value.size();
		} else {
			
			// test for non normal char
			NonNormalCharFound = false;
			for(unsigned int i = 0; i < value.size(); i++) {
				if(!isNormalChar(value[i])) {
					NonNormalCharFound = true;
				}
			}
			
			if(NonNormalCharFound == true) {
				completeLine = key + " = \"" + value + "\"" ;
				KeyStringStart = 0;
				KeyStringLength = key.size();
				ValueStringStart = key.size()+4;
				ValueStringLength = value.size();			
			} else {
				completeLine = key + " = " + value;
				KeyStringStart = 0;
				KeyStringLength = key.size();
				ValueStringStart = key.size()+3;
				ValueStringLength = value.size();			
			}
		}
		if((curKey = new KeyEntry(completeLine,KeyStringStart,KeyStringLength,ValueStringStart,ValueStringLength)) == nullptr)
	    	    throw(std::bad_alloc());
		
		if(curEntry != nullptr) {
			curEntry->nextEntry = curKey;
			curKey->prevEntry = curEntry;
		} else {
			KeyEntry *pKey = curSection->KeyRoot;
			if(pKey == nullptr) {
				// Section has no key yet
				if(curSection->nextEntry == nullptr) {
					// no line after this section declaration
					curSection->nextEntry = curKey;
					curKey->prevEntry = curSection;
				} else {
					// lines after this section declaration
					curSection->nextEntry->prevEntry = curKey;
					curKey->nextEntry = curSection->nextEntry;
					curSection->nextEntry = curKey;
					curKey->prevEntry = curSection;
				}
			} else {
				// Section already has some keys
				while(pKey->nextKey != nullptr) {
					pKey = pKey->nextKey;
				}
				
				if(pKey->nextEntry == nullptr) {
					// no line after this key
					pKey->nextEntry = curKey;
					curKey->prevEntry = pKey;					
				} else {
					// lines after this section declaration
					pKey->nextEntry->prevEntry = curKey;
					curKey->nextEntry = pKey->nextEntry;
					pKey->nextEntry = curKey;
					curKey->prevEntry = pKey;
				}
			}
			
		}
					
		InsertKey(curSection,curKey);
	} else {
		curKey->CompleteLine.replace(curKey->ValueStringBegin,curKey->ValueStringLength,value);
	}
}