// Returns a String with double quotes escaped static const String withEscapedQuotes (String const& string) { String escaped; int i0 = 0; int i; do { i = string.indexOfChar (i0, '"'); if (i == -1) { escaped << string.substring (i0, string.length ()); } else { escaped << string.substring (i0, i) << "\\\""; i0 = i + 1; } } while (i != -1); return escaped; }
// Converts escaped quotes back into regular quotes static const String withUnescapedQuotes (String const& string) { String unescaped; int i0 = 0; int i; do { i = string.indexOfChar (i0, '\\'); if (i == -1) { unescaped << string.substring (i0, string.length ()); } else { // peek if (string.length () > i && string[i + 1] == '\"') { unescaped << string.substring (i0, i) << '"'; i0 = i + 2; } else { unescaped << string.substring (i0, i + 1); i0 = i + 1; } } } while (i != -1); return unescaped; }
RegistryKeyWrapper (String name, const bool createForWriting, const DWORD wow64Flags) : key (0), wideCharValueName (nullptr) { HKEY rootKey = 0; if (name.startsWithIgnoreCase ("HKEY_CURRENT_USER\\")) rootKey = HKEY_CURRENT_USER; else if (name.startsWithIgnoreCase ("HKEY_LOCAL_MACHINE\\")) rootKey = HKEY_LOCAL_MACHINE; else if (name.startsWithIgnoreCase ("HKEY_CLASSES_ROOT\\")) rootKey = HKEY_CLASSES_ROOT; if (rootKey != 0) { name = name.substring (name.indexOfChar ('\\') + 1); const int lastSlash = name.lastIndexOfChar ('\\'); valueName = name.substring (lastSlash + 1); wideCharValueName = valueName.toWideCharPointer(); name = name.substring (0, lastSlash); const wchar_t* const wideCharName = name.toWideCharPointer(); DWORD result; if (createForWriting) RegCreateKeyEx (rootKey, wideCharName, 0, 0, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_QUERY_VALUE | wow64Flags, 0, &key, &result); else RegOpenKeyEx (rootKey, wideCharName, 0, KEY_READ | wow64Flags, &key); } }
String BirdID::returnSpeciesName(int predictedClass) { XmlDocument myDocument (File ("C:/Users/Aneesh/Desktop/BirdID_Data/species.xml")); ScopedPointer<XmlElement> element = myDocument.getDocumentElement(); XmlElement* speciesElement = element->getChildElement(0); int numSpecies = speciesElement->getAllSubText().getIntValue(); speciesElement = element->getChildElement(1); String speciesText = speciesElement->getAllSubText(); int startIndex = 0; String tempString; for(int i=0;i<numSpecies;i++) { int endIndex = speciesText.indexOfChar(startIndex+1,','); if(i==predictedClass-1) { tempString = speciesText.substring(startIndex,endIndex); break; } startIndex = endIndex+1; } element = nullptr; return tempString; }
Font Font::fromString (const String& fontDescription) { int start = 0; int separator = fontDescription.indexOfChar (';'); String family = fontDescription.substring (start, separator).trim(); start = separator + 1; separator = fontDescription.indexOfChar (start, ';'); String style = fontDescription.substring (start, separator).trim(); String sizeAndStyle (fontDescription.substring (separator + 1)); float height = sizeAndStyle.getFloatValue(); if (height <= 0) height = 10.0f; return Font (height, family, style); }
bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress) { auto atSign = possibleEmailAddress.indexOfChar ('@'); return atSign > 0 && possibleEmailAddress.lastIndexOfChar ('.') > (atSign + 1) && ! possibleEmailAddress.endsWithChar ('.'); }
UnitTests::TestList UnitTests::selectTests ( String const& match, TestList const& tests) const noexcept { TestList list; list.ensureStorageAllocated (tests.size ()); int const indexOfDot = match.indexOfChar ('.'); String const package = (indexOfDot == -1) ? match : match.substring (0, indexOfDot); String const testname = (indexOfDot == -1) ? "" : match.substring (indexOfDot + 1, match.length () + 1); if (package != String::empty) { if (testname != String::empty) { // "package.testname" : First test which matches for (int i = 0; i < tests.size(); ++i) { UnitTest* const test = tests [i]; if (package.equalsIgnoreCase (test->getPackageName ()) && testname.equalsIgnoreCase (test->getClassName ())) { list.add (test); break; } } } else { // Get all tests in the package list = selectPackage (package, tests); // If no trailing slash on package, try tests if (list.size () == 0 && indexOfDot == -1) { // Try "package" as a testname list = selectTest (package, tests); } } } else if (testname != String::empty) { list = selectTest (testname, tests); } else { // All non manual tests for (int i = 0; i < tests.size(); ++i) { UnitTest* const test = tests [i]; if (test->getWhen () != UnitTest::runManual) list.add (test); } } return list; }
static bool decomposeURL (const String& url, String& host, String& path, int& port) { if (! url.startsWithIgnoreCase ("http://")) return false; const int nextSlash = url.indexOfChar (7, '/'); int nextColon = url.indexOfChar (7, ':'); if (nextColon > nextSlash && nextSlash > 0) nextColon = -1; if (nextColon >= 0) { host = url.substring (7, nextColon); if (nextSlash >= 0) port = url.substring (nextColon + 1, nextSlash).getIntValue(); else port = url.substring (nextColon + 1).getIntValue(); } else { port = 0; // indicates the default port if (nextSlash >= 0) host = url.substring (7, nextSlash); else host = url.substring (7); } if (nextSlash >= 0) path = url.substring (nextSlash); else path = "/"; return true; }
const String ParseTurn(const String& r, const String& t) { if (!r.startsWith(T("[Ibex]"))) return T("malformed turn file"); int p1=r.indexOf(t); if (p1==-1) return String::empty; //tag not found int p2=r.indexOf(p1,T("=")); if (p2==-1) return String::empty; //equals sign not found int p3=r.indexOfChar(p2,(char)10); return r.substring(p2+1,p3); }
static void addFileWithGroups (Project::Item& group, const RelativePath& file, const String& path) { auto slash = path.indexOfChar (File::getSeparatorChar()); if (slash >= 0) { auto topLevelGroup = path.substring (0, slash); auto remainingPath = path.substring (slash + 1); auto newGroup = group.getOrCreateSubGroup (topLevelGroup); addFileWithGroups (newGroup, file, remainingPath); } else { if (! group.containsChildForFile (file)) group.addRelativeFile (file, -1, false); } }
static void addFileWithGroups (Project::Item& group, const RelativePath& file, const String& path) { const int slash = path.indexOfChar (File::separator); if (slash >= 0) { const String topLevelGroup (path.substring (0, slash)); const String remainingPath (path.substring (slash + 1)); Project::Item newGroup (group.getOrCreateSubGroup (topLevelGroup)); addFileWithGroups (newGroup, file, remainingPath); } else { if (! group.containsChildForFile (file)) group.addRelativeFile (file, -1, false); } }
Font Font::fromString (const String& fontDescription) { const int separator = fontDescription.indexOfChar (';'); String name; if (separator > 0) name = fontDescription.substring (0, separator).trim(); if (name.isEmpty()) name = getDefaultSansSerifFontName(); String sizeAndStyle (fontDescription.substring (separator + 1)); float height = sizeAndStyle.getFloatValue(); if (height <= 0) height = 10.0f; const String style (sizeAndStyle.fromFirstOccurrenceOf (" ", false, false)); return Font (name, style, height); }
static var parseModuleDesc (const StringArray& lines) { DynamicObject* o = new DynamicObject(); var result (o); for (int i = 0; i < lines.size(); ++i) { String line = trimCommentCharsFromStartOfLine (lines[i]); int colon = line.indexOfChar (':'); if (colon >= 0) { String key = line.substring (0, colon).trim(); String value = line.substring (colon + 1).trim(); o->setProperty (key, value); } } return result; }
void Blender::actionListenerCallback(const String &message) { int mixer_id = 0; int channel_id = 0; int mixer_id_index = message.indexOfChar(':') + 1; int channel_id_index = message.indexOfChar('+') + 1; String idStr(String::empty); String type(message.upToFirstOccurrenceOf(":", false, false)); String valStr(message.fromLastOccurrenceOf("=", false, false)); uint32 value = valStr.getIntValue(); bool bUpdateGui = false; if (mixer_id_index >= 0) { idStr = message.substring(mixer_id_index, mixer_id_index+2); mixer_id = idStr.getIntValue(); if (channel_id_index >= 0) { idStr = message.substring(channel_id_index, channel_id_index+2); channel_id = idStr.getIntValue(); if (0 == type.compare("gain")) { int gain = jmin<int>(130, (int)value); m_bl_desc.mixer[mixer_id].channel[channel_id].gain = gain; m_bl_desc.mixer[mixer_id].channel[channel_id].gain_dbv = m_dBvMap[gain]; } else if (0 == type.compare("master_gain")) { // master gain int gain = jmin<int>(130, (int)value); m_bl_desc.mixer[mixer_id].master.gain = gain; m_bl_desc.mixer[mixer_id].master.gain_dbv = m_dBvMap[gain]; } else if (0 == type.compare("pan")) { // channel strip pan m_bl_desc.mixer[mixer_id].channel[channel_id].pan = (int)value; } else if (0 == type.compare("master_mute")) { // master out mute m_bl_desc.mixer[mixer_id].master.muting = (value != 0); } else if (0 == type.compare("mute")) { uint32 muting = (uint32)value; uint32 channel_bit = 1<<channel_id; // channel strip mute if (muting) { // mute m_bl_desc.mixer[mixer_id].mutes |= channel_bit; m_bl_desc.mixer[mixer_id].was_muted |= channel_bit; // handle solos if (0 != m_bl_desc.mixer[mixer_id].solos) { if (m_bl_desc.mixer[mixer_id].solos == channel_bit) { // a solo was active only on that channel, unsolo all and restore mutes m_bl_desc.mixer[mixer_id].solos = 0; m_bl_desc.mixer[mixer_id].mutes = m_bl_desc.mixer[mixer_id].was_muted; bUpdateGui = true; } // other solos are active, unsolo only this one if soloed else if (m_bl_desc.mixer[mixer_id].solos & channel_bit) { m_bl_desc.mixer[mixer_id].solos ^= channel_bit; m_bl_desc.mixer[mixer_id].mutes |= (m_bl_desc.mixer[mixer_id].was_muted & channel_id); bUpdateGui = true; } } } else { // unmute m_bl_desc.mixer[mixer_id].mutes ^= channel_bit; m_bl_desc.mixer[mixer_id].was_muted ^= channel_bit; // handle solos if (0 != m_bl_desc.mixer[mixer_id].solos) { // a solo was active on another channel, solo this one too m_bl_desc.mixer[mixer_id].solos |= channel_bit; bUpdateGui = true; } } } else if (0 == type.compare("solo")) { uint32 soloing = (uint32)value; uint32 channel_bit = 1<<channel_id; if (soloing) { // is this the first soloed channel? if (0 == m_bl_desc.mixer[mixer_id].solos) { // solo m_bl_desc.mixer[mixer_id].solos |= channel_bit; // mute all others m_bl_desc.mixer[mixer_id].mutes = ~channel_bit; bUpdateGui = true; } else { // solo this one also m_bl_desc.mixer[mixer_id].solos |= channel_bit; m_bl_desc.mixer[mixer_id].mutes ^= channel_bit; bUpdateGui = true; } } else { // channel was soloed // was this the only soloed channel? if (m_bl_desc.mixer[mixer_id].solos == channel_bit) { // unsolo all m_bl_desc.mixer[mixer_id].solos = 0; // restore mute states m_bl_desc.mixer[mixer_id].mutes = m_bl_desc.mixer[mixer_id].was_muted; bUpdateGui = true; } else { // other channels are soloed, so unsolo this one only m_bl_desc.mixer[mixer_id].solos ^= channel_bit; // restore mute state if (m_bl_desc.mixer[mixer_id].was_muted & channel_bit) { m_bl_desc.mixer[mixer_id].mutes |= channel_bit; } bUpdateGui = true; } } } else if (0 == type.compare("dirout")) { m_bl_desc.mixer[mixer_id].direct_out = (0 != value); setDirectOut(mixer_id); sendDirout(mixer_id, m_bl_desc.mixer[mixer_id].direct_out); String msg(String::formatted("dirout: mixer id:%d, %d", mixer_id, m_bl_desc.mixer[mixer_id].direct_out)); EventLogger::getInstance()->logMessage(msg); } else if (0 == type.compare("reset")) { for (int i=0; i<m_bl_desc.mixer[mixer_id].num_channels; i++) { m_bl_desc.mixer[mixer_id].channel[i].gain = 101; m_bl_desc.mixer[mixer_id].channel[i].gain_dbv = m_dBvMap[101]; sendChGain(mixer_id, i, 101); m_bl_desc.mixer[mixer_id].channel[i].pan = 0; sendChPan(mixer_id, i, 0); } m_bl_desc.mixer[mixer_id].mutes = 0; m_bl_desc.mixer[mixer_id].was_muted = 0; sendChMutes(mixer_id, m_bl_desc.mixer[mixer_id].mutes); m_bl_desc.mixer[mixer_id].solos = 0; sendChSolos(mixer_id, m_bl_desc.mixer[mixer_id].solos); m_bl_desc.mixer[mixer_id].master.gain = 101; m_bl_desc.mixer[mixer_id].master.gain_dbv = m_dBvMap[101]; sendMasterGain(mixer_id, 101); m_bl_desc.mixer[mixer_id].master.muting = false; sendMasterMute(mixer_id, false); m_bl_desc.mixer[mixer_id].direct_out = 0; setDirectOut(mixer_id); sendDirout(mixer_id, 0); bUpdateGui = true; } // update mixer coeff's mixer_cfg(mixer_id); } if (bUpdateGui) { sendChMutes(mixer_id, m_bl_desc.mixer[mixer_id].mutes); sendChSolos(mixer_id, m_bl_desc.mixer[mixer_id].solos); } } }
static int findStartOfPath (const String& url) { return url.indexOfChar (findStartOfNetLocation (url), '/') + 1; }
// TODO what is this doing in Processor? Should be in MLScale. void MLPluginProcessor::loadScale(const File& f) { MLScale* pScale = mEngine.getScale(); if (!pScale) return; String scaleName = f.getFileNameWithoutExtension(); String scaleDir = f.getParentDirectory().getFileNameWithoutExtension(); String scaleStr = f.loadFileAsString(); const String delim = "\n\r"; int a, b; int contentLines = 0; int ratios = 0; // debug() << "MLPluginProcessor: loading scale " << scaleDir << "/" << scaleName << "\n"; a = b = 0; while(b >= 0) { b = scaleStr.indexOfAnyOf(delim, a, false); // debug() << "[" << a << ", " << b << "] > " << scaleStr.substring(a, b) << "\n"; String inputLine = scaleStr.substring(a, b); if (inputLine[0] != '!') { contentLines++; switch(contentLines) { case 1: { const char* descStr = inputLine.toUTF8(); pScale->setDescription(descStr); const char* nameStr = scaleName.toUTF8(); pScale->setName(nameStr); } break; case 2: { // int notes = inputLine.getIntValue(); // unused pScale->clear(); } break; default: // after 2nd line, add ratios. { // if (inputLine.contains(".")) { double ratio = inputLine.getDoubleValue(); ratios++; pScale->addRatio(ratio); } else { if (inputLine.containsChar('/')) { int s = inputLine.indexOfChar('/'); String numStr = inputLine.substring(0, s); String denomStr = inputLine.substring(s + 1, inputLine.length()); int num = numStr.getIntValue(); int denom = denomStr.getIntValue(); // debug() << "n:" << num << " denom: " << denom << "\n"; if ((num > 0) && (denom > 0)) { ratios++; pScale->addRatio(num, denom); } } else { int num = inputLine.getIntValue(); if (num > 0) { ratios++; pScale->addRatio(num, 1); } } } } break; } } a = b + 2; } if (ratios > 0) { // TODO load .kbm mapping file if one exists pScale->setDefaultMapping(); pScale->recalcRatios(); } broadcastScale(pScale); }
//============================================================================== static bool parseFile (const File& rootFolder, const File& newTargetFile, OutputStream& dest, const File& file, StringArray& alreadyIncludedFiles, const StringArray& includesToIgnore, const StringArray& wildcards, bool isOuterFile, bool stripCommentBlocks) { if (! file.exists()) { std::cout << "!! ERROR - file doesn't exist!"; return false; } StringArray lines; lines.addLines (file.loadFileAsString()); if (lines.size() == 0) { std::cout << "!! ERROR - input file was empty: " << file.getFullPathName(); return false; } bool lastLineWasBlank = true; for (int i = 0; i < lines.size(); ++i) { String line (lines[i]); String trimmed (line.trimStart()); if ((! isOuterFile) && trimmed.startsWith ("//================================================================")) line = String::empty; if (trimmed.startsWithChar ('#') && trimmed.removeCharacters (" \t").startsWithIgnoreCase ("#include\"")) { const int endOfInclude = line.indexOfChar (line.indexOfChar ('\"') + 1, '\"') + 1; const String lineUpToEndOfInclude (line.substring (0, endOfInclude)); const String lineAfterInclude (line.substring (endOfInclude)); const String filename (line.fromFirstOccurrenceOf ("\"", false, false) .upToLastOccurrenceOf ("\"", false, false)); const File targetFile (file.getSiblingFile (filename)); if (targetFile.exists() && targetFile.isAChildOf (rootFolder)) { if (matchesWildcard (filename.replaceCharacter ('\\', '/'), wildcards) && ! includesToIgnore.contains (targetFile.getFileName())) { if (line.containsIgnoreCase ("FORCE_AMALGAMATOR_INCLUDE") || ! alreadyIncludedFiles.contains (targetFile.getFullPathName())) { if (! canFileBeReincluded (targetFile)) alreadyIncludedFiles.add (targetFile.getFullPathName()); dest << newLine << "/*** Start of inlined file: " << targetFile.getFileName() << " ***/" << newLine; if (! parseFile (rootFolder, newTargetFile, dest, targetFile, alreadyIncludedFiles, includesToIgnore, wildcards, false, stripCommentBlocks)) { return false; } dest << "/*** End of inlined file: " << targetFile.getFileName() << " ***/" << newLine << newLine; line = lineAfterInclude; } else { line = String::empty; } } else { line = lineUpToEndOfInclude.upToFirstOccurrenceOf ("\"", true, false) + targetFile.getRelativePathFrom (newTargetFile.getParentDirectory()) .replaceCharacter ('\\', '/') + "\"" + lineAfterInclude; } } } if ((stripCommentBlocks || i == 0) && trimmed.startsWith ("/*") && (i > 10 || ! isOuterFile)) { int originalI = i; String originalLine = line; for (;;) { int end = line.indexOf ("*/"); if (end >= 0) { line = line.substring (end + 2); // If our comment appeared just before an assertion, leave it in, as it // might be useful.. if (lines [i + 1].contains ("assert") || lines [i + 2].contains ("assert")) { i = originalI; line = originalLine; } break; } line = lines [++i]; if (i >= lines.size()) break; } line = line.trimEnd(); if (line.isEmpty()) continue; } line = line.trimEnd(); { // Turn initial spaces into tabs.. int numIntialSpaces = 0; int len = line.length(); while (numIntialSpaces < len && line [numIntialSpaces] == ' ') ++numIntialSpaces; if (numIntialSpaces > 0) { int tabSize = 4; int numTabs = numIntialSpaces / tabSize; line = String::repeatedString ("\t", numTabs) + line.substring (numTabs * tabSize); } if (! line.containsChar ('"')) { // turn large areas of spaces into tabs - this will mess up alignment a bit, but // it's only the amalgamated file, so doesn't matter... line = line.replace (" ", "\t", false); line = line.replace (" ", "\t", false); } } if (line.isNotEmpty() || ! lastLineWasBlank) dest << line << newLine; lastLineWasBlank = line.isEmpty(); } return true; }
ParsedInclude parseInclude (String const& line, String const& trimmed) { ParsedInclude parsed; if (trimmed.startsWithChar ('#')) { const String removed = trimmed.removeCharacters (" \t"); if (removed.startsWithIgnoreCase ("#include\"")) { parsed.endOfInclude = line.indexOfChar (line.indexOfChar ('\"') + 1, '\"') + 1; parsed.filename = line.fromFirstOccurrenceOf ("\"", false, false) .upToLastOccurrenceOf ("\"", false, false); parsed.isIncludeLine = true; parsed.preventReinclude = m_preventReincludes.contains (parsed.filename); parsed.forceReinclude = m_forceReincludes.contains (parsed.filename); } else if (removed.startsWithIgnoreCase ("#include<")) { if (m_checkSystemIncludes) { parsed.endOfInclude = line.indexOfChar (line.indexOfChar ('<') + 1, '>') + 1; parsed.filename = line.fromFirstOccurrenceOf ("<", false, false) .upToLastOccurrenceOf (">", false, false); parsed.isIncludeLine = true; parsed.preventReinclude = m_preventReincludes.contains (parsed.filename); parsed.forceReinclude = m_forceReincludes.contains (parsed.filename); } } else if (removed.startsWithIgnoreCase ("#include")) { String name; #if 1 if (line.contains ("/*")) name = line.fromFirstOccurrenceOf ("#include", false, false) .upToFirstOccurrenceOf ("/*", false, false).trim (); else name = line.fromFirstOccurrenceOf ("#include", false, false).trim (); parsed.endOfInclude = line.upToFirstOccurrenceOf (name, true, false).length (); #else name = line.fromFirstOccurrenceOf ("#include", false, false).trim (); #endif String value = m_macrosDefined [name]; if (m_verbose) std::cout << "name = " << name << "\n"; if (value.startsWithIgnoreCase ("\"")) { parsed.endOfInclude = line.trimEnd().length () + 1; parsed.filename = value.fromFirstOccurrenceOf ("\"", false, false) .upToLastOccurrenceOf ("\"", false, false); parsed.isIncludeLine = true; } else if (value.startsWithIgnoreCase ("<") && m_checkSystemIncludes) { parsed.endOfInclude = line.trimEnd().length () + 1; parsed.filename = value.fromFirstOccurrenceOf ("<", false, false) .upToLastOccurrenceOf (">", false, false); parsed.isIncludeLine = true; } parsed.preventReinclude = parsed.isIncludeLine && m_preventReincludes.contains (name); parsed.forceReinclude = parsed.isIncludeLine && m_forceReincludes.contains (name); } } return parsed; }
String XmlDocument::expandExternalEntity (const String& entity) { if (needToLoadDTD) { if (dtdText.isNotEmpty()) { dtdText = dtdText.trimCharactersAtEnd (">"); tokenisedDTD.addTokens (dtdText, true); if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase ("system") && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString()) { const String fn (tokenisedDTD [tokenisedDTD.size() - 1]); tokenisedDTD.clear(); tokenisedDTD.addTokens (getFileContents (fn), true); } else { tokenisedDTD.clear(); const int openBracket = dtdText.indexOfChar ('['); if (openBracket > 0) { const int closeBracket = dtdText.lastIndexOfChar (']'); if (closeBracket > openBracket) tokenisedDTD.addTokens (dtdText.substring (openBracket + 1, closeBracket), true); } } for (int i = tokenisedDTD.size(); --i >= 0;) { if (tokenisedDTD[i].startsWithChar ('%') && tokenisedDTD[i].endsWithChar (';')) { const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1))); StringArray newToks; newToks.addTokens (parsed, true); tokenisedDTD.remove (i); for (int j = newToks.size(); --j >= 0;) tokenisedDTD.insert (i, newToks[j]); } } } needToLoadDTD = false; } for (int i = 0; i < tokenisedDTD.size(); ++i) { if (tokenisedDTD[i] == entity) { if (tokenisedDTD[i - 1].equalsIgnoreCase ("<!entity")) { String ent (tokenisedDTD [i + 1].trimCharactersAtEnd (">").trim().unquoted()); // check for sub-entities.. int ampersand = ent.indexOfChar ('&'); while (ampersand >= 0) { const int semiColon = ent.indexOf (i + 1, ";"); if (semiColon < 0) { setLastError ("entity without terminating semi-colon", false); break; } const String resolved (expandEntity (ent.substring (i + 1, semiColon))); ent = ent.substring (0, ampersand) + resolved + ent.substring (semiColon + 1); ampersand = ent.indexOfChar (semiColon + 1, '&'); } return ent; } } } setLastError ("unknown entity", true); return entity; }
String File::parseAbsolutePath (const String& p) { if (p.isEmpty()) return String(); #if JUCE_WINDOWS // Windows.. String path (p.replaceCharacter ('/', '\\')); if (path.contains ("\\..\\")) path = removeEllipsis (path); if (path.startsWithChar (separator)) { if (path[1] != separator) { /* When you supply a raw string to the File object constructor, it must be an absolute path. If you're trying to parse a string that may be either a relative path or an absolute path, you MUST provide a context against which the partial path can be evaluated - you can do this by simply using File::getChildFile() instead of the File constructor. E.g. saying "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute path if that's what was supplied, or would evaluate a partial path relative to the CWD. */ jassertfalse; path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path; } } else if (! path.containsChar (':')) { /* When you supply a raw string to the File object constructor, it must be an absolute path. If you're trying to parse a string that may be either a relative path or an absolute path, you MUST provide a context against which the partial path can be evaluated - you can do this by simply using File::getChildFile() instead of the File constructor. E.g. saying "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute path if that's what was supplied, or would evaluate a partial path relative to the CWD. */ // #ZEN(Changed 2016/04/03): Removed jassert, put in DBG call instead due to live constant ed. //jassertfalse; DBG("Passed relative path to juce_File line 130! Jassert Bypassed"); return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName(); } #else // Mac or Linux.. // Yes, I know it's legal for a unix pathname to contain a backslash, but this assertion is here // to catch anyone who's trying to run code that was written on Windows with hard-coded path names. // If that's why you've ended up here, use File::getChildFile() to build your paths instead. jassert ((! p.containsChar ('\\')) || (p.indexOfChar ('/') >= 0 && p.indexOfChar ('/') < p.indexOfChar ('\\'))); String path (p); if (path.contains ("/../")) path = removeEllipsis (path); if (path.startsWithChar ('~')) { if (path[1] == separator || path[1] == 0) { // expand a name of the form "~/abc" path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName() + path.substring (1); } else { // expand a name of type "~dave/abc" const String userName (path.substring (1).upToFirstOccurrenceOf ("/", false, false)); if (struct passwd* const pw = getpwnam (userName.toUTF8())) path = addTrailingSeparator (pw->pw_dir) + path.fromFirstOccurrenceOf ("/", false, false); } } else if (! path.startsWithChar (separator)) { #if JUCE_DEBUG || JUCE_LOG_ASSERTIONS if (! (path.startsWith ("./") || path.startsWith ("../"))) { /* When you supply a raw string to the File object constructor, it must be an absolute path. If you're trying to parse a string that may be either a relative path or an absolute path, you MUST provide a context against which the partial path can be evaluated - you can do this by simply using File::getChildFile() instead of the File constructor. E.g. saying "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute path if that's what was supplied, or would evaluate a partial path relative to the CWD. */ jassertfalse; #if JUCE_LOG_ASSERTIONS Logger::writeToLog ("Illegal absolute path: " + path); #endif } #endif return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName(); } #endif while (path.endsWithChar (separator) && path != separatorString) // careful not to turn a single "/" into an empty string. path = path.dropLastCharacters (1); return path; }
//============================================================================== String File::parseAbsolutePath (const String& p) { if (p.isEmpty()) return String::empty; #if JUCE_WINDOWS // Windows.. String path (p.replaceCharacter ('/', '\\')); if (path.startsWithChar (File::separator)) { if (path[1] != File::separator) { /* When you supply a raw string to the File object constructor, it must be an absolute path. If you're trying to parse a string that may be either a relative path or an absolute path, you MUST provide a context against which the partial path can be evaluated - you can do this by simply using File::getChildFile() instead of the File constructor. E.g. saying "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute path if that's what was supplied, or would evaluate a partial path relative to the CWD. */ jassertfalse; path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path; } } else if (! path.containsChar (':')) { /* When you supply a raw string to the File object constructor, it must be an absolute path. If you're trying to parse a string that may be either a relative path or an absolute path, you MUST provide a context against which the partial path can be evaluated - you can do this by simply using File::getChildFile() instead of the File constructor. E.g. saying "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute path if that's what was supplied, or would evaluate a partial path relative to the CWD. */ jassertfalse; return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName(); } #else // Mac or Linux.. // Yes, I know it's legal for a unix pathname to contain a backslash, but this assertion is here // to catch anyone who's trying to run code that was written on Windows with hard-coded path names. // If that's why you've ended up here, use File::getChildFile() to build your paths instead. jassert ((! p.containsChar ('\\')) || (p.indexOfChar ('/') >= 0 && p.indexOfChar ('/') < p.indexOfChar ('\\'))); String path (p); if (path.startsWithChar ('~')) { if (path[1] == File::separator || path[1] == 0) { // expand a name of the form "~/abc" path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName() + path.substring (1); } else { // expand a name of type "~dave/abc" const String userName (path.substring (1).upToFirstOccurrenceOf ("/", false, false)); struct passwd* const pw = getpwnam (userName.toUTF8()); if (pw != nullptr) path = addTrailingSeparator (pw->pw_dir) + path.fromFirstOccurrenceOf ("/", false, false); } } else if (! path.startsWithChar (File::separator)) { /* When you supply a raw string to the File object constructor, it must be an absolute path. If you're trying to parse a string that may be either a relative path or an absolute path, you MUST provide a context against which the partial path can be evaluated - you can do this by simply using File::getChildFile() instead of the File constructor. E.g. saying "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute path if that's what was supplied, or would evaluate a partial path relative to the CWD. */ jassert (path.startsWith ("./") || path.startsWith ("../")); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD) return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName(); } #endif while (path.endsWithChar (separator) && path != separatorString) // careful not to turn a single "/" into an empty string. path = path.dropLastCharacters (1); return path; }
bool CSPIniReadWrite::loadFromBuffer(byte* pBuffer, uint length) { if (pBuffer) { delAllSections(); uint i = 0; uint start = 0; uint end = 0; String strOneLine; // 一行文本内容 String strKey; // 键名 String strValue; // 键值 Section *myPG = nullptr; // 段的iter int squarebrackets_left = -1; // 左中括号的位置 int squarebrackets_right = - 1; // 右中括号的位置 int equalsymbol = -1; // 等号的位置 //unicode16 if (length >= 2 && pBuffer[0] == 0xFF && pBuffer[1] == 0xFE) { CharPointer_UTF16::CharType byTemp; CharPointer_UTF16::CharType* pTBuffer = (CharPointer_UTF16::CharType*)(pBuffer + 2); length = (length - 2)/2; // i = 2; // start = i; while (1) { byTemp = pTBuffer[i]; if (byTemp != 0 && byTemp != L'\r' && byTemp != L'\n' && i < length) { i++; } else { end = i; if (start == end) { if (byTemp == 0 || i >= length) { break; } else { start = end + 1; i = start; continue; } } //处理一行数据 strOneLine = String(CharPointer_UTF16(pTBuffer + start), CharPointer_UTF16(pTBuffer + end)).trim(); // 判断是否是空行 if (strOneLine.isEmpty()) { if (byTemp == 0 || i >= length) { break; } else { start = end + 1; i = start; continue; } } squarebrackets_left = strOneLine.indexOfChar(L'['); squarebrackets_right = strOneLine.indexOfChar(L']'); // 以下处理建 if ((squarebrackets_left != -1) && (squarebrackets_right != -1) && (squarebrackets_left < squarebrackets_right)) { int equalPos = strOneLine.indexOfChar(L'='); if (equalPos == -1 || (equalPos > squarebrackets_left && equalPos < squarebrackets_right)) { strKey = strOneLine.substring(squarebrackets_left + 1, squarebrackets_right); myPG = new Section(strKey); m_ini.push_back(myPG); if (byTemp == 0 || i >= length) { break; } else { start = end + 1; i = start; continue; } } } // 以下处理key equalsymbol = strOneLine.indexOfChar(L'='); strKey = strOneLine.substring(0, equalsymbol).trim(); // 取得键名 // 取得键值 strValue = strOneLine.substring(equalsymbol + 1, strOneLine.length()).trim(); m_ini.back()->m_tKeys.insert(pair_Key(strKey, strValue)); if (byTemp == 0 || i >= length) { break; } start = end + 1; i = start; } } } //UTF8 else if (length >= 3 && pBuffer[0] == 0xEF && pBuffer[1] == 0xBB && pBuffer[2] == 0xBF) { i = 3;// 要先减去标志位 start = i; CharPointer_UTF8::CharType byTemp; while (1) { byTemp = pBuffer[i]; if (byTemp != 0 && byTemp != '\r' && byTemp != '\n' && i < length) { i++; } else { end = i; if (start == end) { if (byTemp == 0 || i >= length) { break; } else { start = end + 1; i = start; continue; } } //处理一行数据 strOneLine = String(CharPointer_UTF8((CharPointer_UTF8::CharType*)(pBuffer + start)), CharPointer_UTF8((CharPointer_UTF8::CharType*)(pBuffer + end))).trim(); // 判断是否是空行 if (strOneLine.isEmpty()) { if (byTemp == 0 || i >= length) { break; } else { start = end + 1; i = start; continue; } } squarebrackets_left = strOneLine.indexOfChar(L'['); squarebrackets_right = strOneLine.indexOfChar(L']'); // 以下处理建 if ((squarebrackets_left != -1) && (squarebrackets_right != -1) && (squarebrackets_left < squarebrackets_right)) { int equalPos = strOneLine.indexOfChar(L'='); if (equalPos == -1 || (equalPos > squarebrackets_left && equalPos < squarebrackets_right)) { strKey = strOneLine.substring(squarebrackets_left + 1, squarebrackets_right); myPG = new Section(strKey); m_ini.push_back(myPG); if (byTemp == 0 || i >= length) { break; } else { start = end + 1; i = start; continue; } } } // 以下处理key equalsymbol = strOneLine.indexOfChar(L'='); strKey = strOneLine.substring(0, equalsymbol).trim(); // 取得键名 // 取得键值 strValue = strOneLine.substring(equalsymbol + 1, strOneLine.length()).trim(); m_ini.back()->m_tKeys.insert(pair_Key(strKey, strValue)); if (byTemp == 0 || i >= length) { break; } start = end + 1; i = start; } } } else { CharPointer_ASCII::CharType byTemp; while (1) { byTemp = pBuffer[i]; if (byTemp != 0 && byTemp != '\r' && byTemp != '\n' && i < length) { i++; } else { end = i; if (start == end) { if (byTemp == 0 || i >= length) { break; } else { start = end + 1; i = start; continue; } } //处理一行数据 strOneLine = String((CharPointer_ASCII::CharType*)(pBuffer + start), end - start).trim(); // 判断是否是空行 if (strOneLine.isEmpty()) { if (byTemp == 0 || i >= length) { break; } else { start = end + 1; i = start; continue; } } squarebrackets_left = strOneLine.indexOfChar(L'['); squarebrackets_right = strOneLine.indexOfChar(L']'); // 以下处理建 if ((squarebrackets_left != -1) && (squarebrackets_right != -1) && (squarebrackets_left < squarebrackets_right)) { int equalPos = strOneLine.indexOfChar(L'='); if (equalPos == -1 || (equalPos > squarebrackets_left && equalPos < squarebrackets_right)) { strKey = strOneLine.substring(squarebrackets_left + 1, squarebrackets_right); myPG = new Section(strKey); m_ini.push_back(myPG); if (byTemp == 0 || i >= length) { break; } else { start = end + 1; i = start; continue; } } } // 以下处理key equalsymbol = strOneLine.indexOfChar(L'='); if (equalsymbol != -1) { strKey = strOneLine.substring(0, equalsymbol).trim(); // 取得键名 // 取得键值 strValue = strOneLine.substring(equalsymbol + 1, strOneLine.length()).trim(); m_ini.back()->m_tKeys.insert(pair_Key(strKey, strValue)); } if (byTemp == 0 || i >= length) { break; } start = end + 1; i = start; } } } return true; } return false; }