void StLangMap::parseLine(const StString& theLine) { if(myIsHeaderSection) { myIsHeaderSection = !(theLine == StString(HEADER_SECTION_DELIM)); } for(StUtf8Iter anIter = theLine.iterator(); *anIter != 0; ++anIter) { if(*anIter != stUtf32_t('=')) { // not interesting continue; } size_t aKey = size_t(std::atol(theLine.subString(0, anIter.getIndex()).toCString())); // get value without quotes StString aValue = theLine.subString(anIter.getIndex() + 2, theLine.getLength() - 1); ///TODO (Kirill Gavrilov#9) add all replacements for(anIter = aValue.iterator(); *anIter != 0; ++anIter) { if(*anIter.getBufferHere() == stUtf8_t('\\') && *anIter.getBufferNext() == stUtf8_t('n')) { // this is a hacking code in fact... *(stUtf8_t* )anIter.getBufferHere() = stUtf8_t(' '); *(stUtf8_t* )anIter.getBufferNext() = stUtf8_t('\n'); } } myMap.insert(std::pair<size_t, StString>(aKey, aValue)); return; } }
unsigned int decodeHotKey(const StString& theString) { unsigned int aKey = 0; if(theString.isEmpty()) { return aKey; } // decode flags (split by + separator) StUtf8Iter aFrom = theString.iterator(); StUtf8Iter anIter = theString.iterator(); for(; *anIter != 0; ++anIter) { if(*anIter == stUtf32_t('+')) { if(anIter.getIndex() == 0) { return ST_VK_OEM_PLUS; // single '+' } const StCStringUtf8 aSubStr = { aFrom.getBufferHere(), size_t(anIter.getBufferHere() - aFrom.getBufferHere()), anIter.getIndex() - aFrom.getIndex() }; if(aSubStr.isEquals(THE_VKEYS_NAMES[ST_VK_SHIFT])) { aKey |= ST_VF_SHIFT; } else if(aSubStr.isEquals(THE_VKEYS_NAMES[ST_VK_CONTROL])) { aKey |= ST_VF_CONTROL; } aFrom = anIter; ++aFrom; } } // decode VKey itself const StCStringUtf8 aSubStr = { aFrom.getBufferHere(), size_t(anIter.getBufferHere() - aFrom.getBufferHere()), anIter.getIndex() - aFrom.getIndex() }; if(aSubStr.Size == 1) { // optimized code for letters if(*aSubStr.String >= 'A' && *aSubStr.String <= 'Z') { aKey |= (unsigned int )*aSubStr.String; return aKey; } else if(*aSubStr.String >= '0' && *aSubStr.String <= '9') { aKey |= (unsigned int )*aSubStr.String; return aKey; } } for(unsigned int aKeyIter = 0; aKeyIter <= 223; ++aKeyIter) { if(aSubStr.isEquals(THE_VKEYS_NAMES[aKeyIter])) { aKey |= aKeyIter; break; } } return aKey; }
StString StFileNode::getExtension(const StString& theFileName) { size_t aPntId = size_t(-1); for(StUtf8Iter anIter = theFileName.iterator(); *anIter != 0; ++anIter) { if(*anIter == stUtf32_t('.')) { aPntId = anIter.getIndex(); } } return (aPntId != size_t(-1)) ? theFileName.subString(aPntId + 1, theFileName.getLength()) : StString(); }
void StDictEntry::parseString(const StString& theString) { for(StUtf8Iter anIter = theString.iterator(); *anIter != 0; ++anIter) { if(*anIter == stUtf32_t('=')) { myKey = theString.subString(0, anIter.getIndex()); myValue = theString.subString(anIter.getIndex() + 1, theString.getLength()).unquoted(); return; } } myKey = theString; }
bool stUtfTools::isInteger(const StString& theString) { StUtf8Iter anIter = theString.iterator(); // TODO (Kirill Gavrilov#9) + and - should be followed by numbers! if(!isNumChar(*anIter) && (*anIter != stUtf32_t('+')) && (*anIter != stUtf32_t('-'))) { return false; } ++anIter; for(; *anIter != 0; ++anIter) { if(!isNumChar(*anIter)) { return false; } } return true; }
StString StProcess::getProcessFolder() { StString aFullPath = getProcessFullPath(); size_t aLastSplit = size_t(-1); for(StUtf8Iter anIter = aFullPath.iterator(); *anIter != 0; ++anIter) { if(*anIter == stUtf32_t(SYS_FS_SPLITTER)) { aLastSplit = anIter.getIndex(); } } if(aLastSplit != size_t(-1)) { return aFullPath.subString(0, aLastSplit + 1); // including trailing separator! } else { return StString(); } }
StString StProcess::getProcessName() { StString aFullPath = getProcessFullPath(); size_t aLastSplit = size_t(-1); for(StUtf8Iter anIter = aFullPath.iterator(); *anIter != 0; ++anIter) { if(*anIter == stUtf32_t(SYS_FS_SPLITTER)) { aLastSplit = anIter.getIndex(); } } if(aLastSplit != size_t(-1)) { return aFullPath.subString(aLastSplit + 1, aFullPath.getLength()); } else { return aFullPath; } }
void StFileNode::getNameAndExtension(const StString& theFileName, StString& theName, StString& theExtension) { size_t aLastPnt = size_t(-1); for(StUtf8Iter anIter = theFileName.iterator(); *anIter != 0; ++anIter) { if(*anIter == stUtf32_t('.')) { aLastPnt = anIter.getIndex(); } } if(aLastPnt != size_t(-1)) { theName = theFileName.subString(0, aLastPnt); theExtension = theFileName.subString(aLastPnt + 1, theFileName.getLength()); } else { theName = theFileName; theExtension = StString(); } }
void StFileNode::getFolderAndFile(const StString& theFilePath, StString& theFolder, StString& theFileName) { size_t aLastSplit = size_t(-1); for(StUtf8Iter anIter = theFilePath.iterator(); *anIter != 0; ++anIter) { if(*anIter == stUtf32_t(SYS_FS_SPLITTER)) { aLastSplit = anIter.getIndex(); } } if(aLastSplit != size_t(-1)) { theFolder = theFilePath.subString(0, aLastSplit); theFileName = theFilePath.subString(aLastSplit + 1, theFilePath.getLength()); } else { theFolder = StString(); theFileName = theFilePath; } }
StString StFileNode::getFolderUp(const StString& thePath) { size_t aLastSplit = size_t(-1); size_t aPreSplit = size_t(-1); for(StUtf8Iter anIter = thePath.iterator(); *anIter != 0; ++anIter) { if(*anIter == stUtf32_t(SYS_FS_SPLITTER)) { aPreSplit = aLastSplit; aLastSplit = anIter.getIndex(); } } if(aLastSplit != size_t(-1) && aLastSplit + 1 == thePath.getLength()) { aLastSplit = aPreSplit; } if(aLastSplit == size_t(-1)) { return StString(); } return thePath.subString(0, aLastSplit); }
void StDictionary::parseString(const StString& theString) { size_t aStart = 0; bool isInQuotes1 = false; bool isInQuotes2 = false; for(StUtf8Iter anIter = theString.iterator();; ++anIter) { if(*anIter == stUtf32_t('\'') && !isInQuotes2) { isInQuotes1 = !isInQuotes1; } else if(*anIter == stUtf32_t('\"') && !isInQuotes1) { isInQuotes2 = !isInQuotes2; } else if((*anIter == stUtf32_t('\n') || *anIter == stUtf32_t('\0')) && !isInQuotes1 && !isInQuotes2) { StDictEntry aNewArgument; aNewArgument.parseString(theString.subString(aStart, anIter.getIndex())); add(aNewArgument); aStart = anIter.getIndex() + 1; } if(*anIter == 0) { return; } } }