Example #1
0
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;
    }
}
Example #2
0
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;
}
Example #3
0
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();
    }
}
Example #4
0
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;
    }
}
Example #5
0
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();
}
Example #6
0
StString StProcess::getAbsolutePath(const StString& thePath) {
    StString aPath;
    if(thePath.isStartsWith(ST_FILE_PROTOCOL)) {
        const StString aData = thePath.subString(ST_FILE_PROTOCOL.getLength(), thePath.getLength());
        aPath.fromUrl(aData);
    } else {
        aPath = thePath;
    }

    if(StFileNode::isAbsolutePath(aPath)) {
        return aPath;
    }
    return StProcess::getWorkingFolder() + aPath; // make absolute path
}
Example #7
0
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();
    }
}
Example #8
0
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;
    }
}
Example #9
0
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);
}
Example #10
0
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;
        }
    }
}
Example #11
0
bool StLibrary::load(const StString& thePath) {
    // this is probably some logical error in the code if close() wasn't explicitly called before!
    ST_ASSERT(!isOpened(), "StLibrary::load() - library is already opened!");
    close();
    StString aDinLibExt = StString(ST_DLIB_SUFFIX);
    if(thePath.isEndsWithIgnoreCase(aDinLibExt)) {
        // got the full path?
        myPath = thePath;
        myLibH = DLibLoadFull(myPath);
        if(myLibH == NULL) {
            // try to remove an extension
            myPath = thePath.subString(0, thePath.getLength() - aDinLibExt.getLength());
            myLibH = DLibLoad(myPath);
        }
    } else {
        // got short name?
        myPath = thePath;
        myLibH = DLibLoad(myPath);
    }
    return isOpened();
}
Example #12
0
void StAndroidGlue::setOpenPath(const jstring  theOpenPath,
                                const jstring  theMimeType,
                                const jboolean theIsLaunchedFromHistory) {
    JNIEnv* aJniEnv = myActivity->env;
    StString anOpenPath = stStringFromJava(aJniEnv, theOpenPath);
    StString aMimeType  = stStringFromJava(aJniEnv, theMimeType);

    const StString ST_FILE_PROTOCOL("file://");
    if(anOpenPath.isStartsWith(ST_FILE_PROTOCOL)) {
        const size_t   aCutFrom = ST_FILE_PROTOCOL.getLength();
        const StString aPath    = anOpenPath.subString(aCutFrom, (size_t )-1);
        anOpenPath.fromUrl(aPath);
    }

    StMutexAuto aLock(myFetchLock);
    if(myCreatePath.isEmpty()) {
        myCreatePath = anOpenPath;
    }

    // ignore outdated intent from history list - use C++ recent list instead
    if(!theIsLaunchedFromHistory) {
        myDndPath = anOpenPath;
    }
}
Example #13
0
StHandle<StOpenInfo> StApplication::parseProcessArguments() {
    StHandle<StOpenInfo> anInfo = new StOpenInfo();

    StArrayList<StString> anArguments = StProcess::getArguments();
    StArgumentsMap anOpenFileArgs;
    size_t aFilesCount = 0;
    bool isFilesSection = false;
    const StString ARGUMENT_FILES_SECTION     = '-';
    const StString ARGUMENT_ANY               = "--";
    const StString ARGUMENT_HELP              = "help";
    const StString ARGUMENT_FILE              = "file";
    const StString ARGUMENT_LEFT_VIEW         = "left";
    const StString ARGUMENT_RIGHT_VIEW        = "right";
    // parse extra parameters
    for(size_t aParamIter = 1; aParamIter < anArguments.size(); ++aParamIter) {
        StString aParam = anArguments[aParamIter];
        ///ST_DEBUG_LOG("aParam= '" + aParam + "'");
        if(isFilesSection) {
            // file name
            StString aFilePath = StProcess::getAbsolutePath(aParam);
            anOpenFileArgs.add(StArgument(ARGUMENT_FILE + aFilesCount++, aFilePath));
            if(!anInfo->hasPath()) {
                // first file determines MIME type (needed to autoselect Drawer plugin)
                anInfo->setPath(aFilePath);
            }
        } else if(aParam == ARGUMENT_FILES_SECTION) {
            isFilesSection = true;
        } else if(aParam.isStartsWith(ARGUMENT_ANY)) {
            // argument
            StArgument anArg; anArg.parseString(aParam.subString(2, aParam.getLength())); // cut suffix --

            if(anArg.getKey().isEqualsIgnoreCase(ARGUMENT_HELP)) {
                return NULL;
            } else if(anArg.getKey().isEqualsIgnoreCase(ARGUMENT_LEFT_VIEW)) {
                // left view
                anArg.setValue(StProcess::getAbsolutePath(anArg.getValue()));
                anOpenFileArgs.add(anArg);
                anInfo->setPath(anArg.getValue()); // left file always determines MIME type
            } else if(anArg.getKey().isEqualsIgnoreCase(ARGUMENT_RIGHT_VIEW)) {
                // right view
                anArg.setValue(StProcess::getAbsolutePath(anArg.getValue()));
                anOpenFileArgs.add(anArg);
                if(!anInfo->hasPath()) {
                    anInfo->setPath(anArg.getValue());
                }
            } else {
                // pass argument unchanged
                anOpenFileArgs.add(anArg);
            }
        } else {
            // file name
            StString aFilePath = StProcess::getAbsolutePath(aParam);
            anOpenFileArgs.add(StArgument(ARGUMENT_FILE + aFilesCount++, aFilePath));
            if(!anInfo->hasPath()) {
                // first file determines MIME type (needed to autoselect Drawer plugin)
                anInfo->setPath(aFilePath);
            }
        }
    }

    anInfo->setArgumentsMap(anOpenFileArgs);
    return anInfo;
}