Example #1
0
String String::toUpper()
{
	String text = getString();
	for (int i = 0; i < _size; i++)
	{
		text.at(i) = toupper(text.at(i));
	}
	return text;
}
Example #2
0
String String::reverse()
{
	String value = *this;

	int half = _size / 2;
	char temp;
	for (int i = 0; i < half; i++)
	{
		temp = value[i];
		value.at(i) = value[_size - i];
		value.at(_size - i) = temp;
	}

	return value;
}
Example #3
0
    String String::toUppercase(size_t begin, size_t end) const
    {
        String upper = *this;

        for(std::size_t i = begin; i < std::min(getSize(), end); i++)
        {
            upper.at(i) = Character::toUpper(at(i));
        }

        return upper;
    }
Example #4
0
	//---------------------------------------------------------------------
	uint32 StreamSerialiser::makeIdentifier(const String& code)
	{
		assert(code.length() <= 4 && "Characters after the 4th are being ignored");
		uint32 ret = 0;
		size_t c = std::min((size_t)4, code.length());
		for (size_t i = 0; i < c; ++i)
		{
			ret += (code.at(i) << (i * 8));
		}
		return ret;

	}
void CallTipManager::load(wxString& path)
{
	// TODO: Clear tips list

	std::ifstream fp;
	fp.open(path, std::ios::in | std::ios::binary);
	if(fp)
	{
		DataStreamPtr stream(new FileStreamDataStream(path.c_str(), &fp, false));

		int index = -1;
		String line;
		String key;
		while(!stream->eof())
		{
			line = stream->getLine();

			// Ignore blank lines and comments (comment lines start with '#')
			if(line.length() > 0 && line.at(0) != '#')
			{
				if(line.at(0) == '[')
				{
					int endBrace = (int)line.find(']');
					if(endBrace != -1)
					{
						key = line.substr(1, endBrace - 1);
					}
				}
				else
				{
					if(mCallTips.find(key) != mCallTips.end())
						mCallTips[key] = mCallTips[key] + "\n" + line;
					else
						mCallTips[key] = line;
				}
			}
		}
	}
}
//determine number of attachmentPoints given a fragmented molecule,
void attachmentPoints(String smi2){
//Creates an Integer array for storing count results
	int attachments;
	int asterisks = 0;
	bool match = false;

	//loop //if (smi2[i] == '*')
	for (int i = 0; i < smi2.length(); i ++) {
	    if (smi2.at(i) == '*') {
	        asterisks++;
	        match = true;
	        attachments = asterisks++;
	        break;
	   }
    }
}
Example #7
0
/**
 * All numbers become roman numerals.
 */
String romanFilter(const String& src, bool upperCase)
{
    String dest;

    for(int i = 0; i < src.size(); )
    {
        if(!src[i].isDigit())
        {
            dest += src[i++];
            continue;
        }

        // Found a number. Read all the digits.
        int start = i;
        while(i < src.size() && src.at(i).isDigit()) ++i;
        int number = src.mid(start, i).toInt();
        dest += stringCase(romanCounter(number), upperCase? UPPERCASE_ALL : LOWERCASE_ALL);
    }
    return dest;
}
Example #8
0
String TextureConverterDialog::NormalizePath(const String &pathname)
{
    Vector<String> tokens;
    Split(pathname, "/", tokens);
    
    String retString = "";
    int32 skipCount = 0;
    for(int32 i = tokens.size() - 1; i >= 0; --i)
    {
        if(tokens[i] == "..")
        {
            ++skipCount;
        }
        else if(skipCount)
        {
            i -= skipCount;
            skipCount = 0;
        }
        else 
        {
            if(i == tokens.size() - 1)
            {
                retString = tokens[i];
            }
            else 
            {
                retString = tokens[i] + "/" + retString;
            }
        }
    }
    
    if(pathname.length() && '/' == pathname.at(0))
    {
        retString = "/" + retString;
    }
    
    return retString;
}
    //---------------------------------------------------------------------
    void GLSLProgramManagerCommon::extractConstantDefs(const String& src,
        GpuNamedConstants& defs, const String& filename)
    {
        // Parse the output string and collect all uniforms
        // NOTE this relies on the source already having been preprocessed
        // which is done in GLSLProgram::loadFromSource
        String line;
        String::size_type currPos = src.find("uniform");
        while (currPos != String::npos)
        {
            // Now check for using the word 'uniform' in a larger string & ignore
            bool inLargerString = false;
            if (currPos != 0)
            {
                char prev = src.at(currPos - 1);
                if (prev != ' ' && prev != '\t' && prev != '\r' && prev != '\n'
                    && prev != ';')
                    inLargerString = true;
            }
            if (!inLargerString && currPos + 7 < src.size())
            {
                char next = src.at(currPos + 7);
                if (next != ' ' && next != '\t' && next != '\r' && next != '\n')
                    inLargerString = true;
            }

            // skip 'uniform'
            currPos += 7;

            if (!inLargerString)
            {
                String::size_type endPos;
                GpuSharedParametersPtr blockSharedParams;

                // Check for a type. If there is one, then the semicolon is missing
                // otherwise treat as if it is a uniform block
                String::size_type lineEndPos = src.find_first_of("\n\r", currPos);
                line = src.substr(currPos, lineEndPos - currPos);
                StringVector parts = StringUtil::split(line, " \t");
                StringToEnumMap::iterator typei = mTypeEnumMap.find(parts.front());
                if (typei == mTypeEnumMap.end())
                {
                    // Gobble up the external name
                    String externalName = parts.front();

                    // Now there should be an opening brace
                    String::size_type openBracePos = src.find("{", currPos);
                    if (openBracePos != String::npos)
                    {
                        currPos = openBracePos + 1;
                    }
                    else
                    {
                        LogManager::getSingleton().logMessage("Missing opening brace in GLSL Uniform Block in file "
                                                              + filename);
                        break;
                    }

                    // First we need to find the internal name for the uniform block
                    String::size_type endBracePos = src.find("}", currPos);

                    // Find terminating semicolon
                    currPos = endBracePos + 1;
                    endPos = src.find(";", currPos);
                    if (endPos == String::npos)
                    {
                        // problem, missing semicolon, abort
                        break;
                    }

                    // TODO: We don't need the internal name. Just skip over to the end of the block
                    // But we do need to know if this is an array of blocks. Is that legal?

// Find the internal name.
// This can be an array.
//                    line = src.substr(currPos, endPos - currPos);
//                    StringVector internalParts = StringUtil::split(line, ", \t\r\n");
//                    String internalName = "";
//                    uint16 arraySize = 0;
//                    for (StringVector::iterator i = internalParts.begin(); i != internalParts.end(); ++i)
//                    {
//                        StringUtil::trim(*i);
//                        String::size_type arrayStart = i->find("[", 0);
//                        if (arrayStart != String::npos)
//                        {
//                            // potential name (if butted up to array)
//                            String name = i->substr(0, arrayStart);
//                            StringUtil::trim(name);
//                            if (!name.empty())
//                                internalName = name;
//
//                            String::size_type arrayEnd = i->find("]", arrayStart);
//                            String arrayDimTerm = i->substr(arrayStart + 1, arrayEnd - arrayStart - 1);
//                            StringUtil::trim(arrayDimTerm);
//                            arraySize = StringConverter::parseUnsignedInt(arrayDimTerm);
//                        }
//                        else
//                        {
//                            internalName = *i;
//                        }
//                    }
//
//                    // Ok, now rewind and parse the individual uniforms in this block
//                    currPos = openBracePos + 1;
//                    blockSharedParams = GpuProgramManager::getSingleton().getSharedParameters(externalName);
//                    if(blockSharedParams.isNull())
//                        blockSharedParams = GpuProgramManager::getSingleton().createSharedParameters(externalName);
//                    do
//                    {
//                        lineEndPos = src.find_first_of("\n\r", currPos);
//                        endPos = src.find(";", currPos);
//                        line = src.substr(currPos, endPos - currPos);
//
//                        // TODO: Give some sort of block id
//                        // Parse the normally structured uniform
//                        parseIndividualConstant(src, defs, currPos, filename, blockSharedParams);
//                        currPos = lineEndPos + 1;
//                    } while (endBracePos > currPos);
                }
                else
                {
                    // find terminating semicolon
                    endPos = src.find(";", currPos);
                    if (endPos == String::npos)
                    {
                        // problem, missing semicolon, abort
                        break;
                    }
                    
                    parseIndividualConstant(src, defs, currPos, filename, blockSharedParams);
                }
                line = src.substr(currPos, endPos - currPos);
            } // not commented or a larger symbol
            
            // Find next one
            currPos = src.find("uniform", currPos);
        }
    }
Example #10
0
	//-----------------------------------------------------------------------
	StringVector StringUtil::tokenise( const String& str, const String& singleDelims, const String& doubleDelims, unsigned int maxSplits)
	{
        StringVector ret;
        // Pre-allocate some space for performance
        ret.reserve(maxSplits ? maxSplits+1 : 10);    // 10 is guessed capacity for most case

        unsigned int numSplits = 0;
		String delims = singleDelims + doubleDelims;

		// Use STL methods 
        size_t start, pos;
		char curDoubleDelim = 0;
        start = 0;
        do 
        {
			if (curDoubleDelim != 0)
			{
				pos = str.find(curDoubleDelim, start);
			}
			else
			{
				pos = str.find_first_of(delims, start);
			}

            if (pos == start)
            {
				char curDelim = str.at(pos);
				if (doubleDelims.find_first_of(curDelim) != String::npos)
				{
					curDoubleDelim = curDelim;
				}
                // Do nothing
                start = pos + 1;
            }
            else if (pos == String::npos || (maxSplits && numSplits == maxSplits))
            {
				if (curDoubleDelim != 0)
				{
					//Missing closer. Warn or throw exception?
				}
                // Copy the rest of the string
                ret.push_back( str.substr(start) );
                break;
            }
            else
            {
				if (curDoubleDelim != 0)
				{
					curDoubleDelim = 0;
				}

				// Copy up to delimiter
				ret.push_back( str.substr(start, pos - start) );
				start = pos + 1;
            }
			if (curDoubleDelim == 0)
			{
				// parse up to next real data
				start = str.find_first_not_of(singleDelims, start);
			}
            
            ++numSplits;

        } while (pos != String::npos);

        return ret;
    }
Example #11
0
int FindFileJob::execute()
{
    std::shared_ptr<Project> proj = project();
    if (!proj) {
        return 1;
    }
    if (!proj->fileManager())
        return 1;
    const Path srcRoot = proj->path();
    assert(srcRoot.endsWith('/'));

    enum Mode {
        All,
        FilePath,
        Regex,
        Pattern,
    } mode = All;

    String::CaseSensitivity cs = String::CaseSensitive;
    if (queryFlags() & QueryMessage::MatchRegex) {
        mode = Regex;
    } else if (!mPattern.isEmpty()) {
        mode = mPattern[0] == '/' ? FilePath : Pattern;
    }
    if (queryFlags() & QueryMessage::MatchCaseInsensitive)
        cs = String::CaseInsensitive;

    String out;
    out.reserve(PATH_MAX);
    const bool absolutePath = queryFlags() & QueryMessage::AbsolutePath;
    if (absolutePath)
        out.append(srcRoot);
    const Files& dirs = proj->files();
    assert(proj->fileManager());
    if (dirs.isEmpty())
        proj->fileManager()->load(FileManager::Synchronous);
    Files::const_iterator dirit = dirs.begin();
    bool foundExact = false;
    const int patternSize = mPattern.size();
    List<String> matches;
    const bool preferExact = queryFlags() & QueryMessage::FindFilePreferExact;
    int ret = 1;
    bool firstElisp = queryFlags() & QueryMessage::Elisp;

    auto writeFile = [this, &firstElisp](const Path &path) {
        if (firstElisp) {
            firstElisp = false;
            if (!write("(list", DontQuote))
                return false;
        }
        return write(path);
    };
    while (dirit != dirs.end()) {
        const Path &dir = dirit->first;
        if (dir.size() < srcRoot.size()) {
            continue;
        } else {
            out.append(dir.constData() + srcRoot.size(), dir.size() - srcRoot.size());
        }

        const Set<String> &files = dirit->second;
        for (Set<String>::const_iterator it = files.begin(); it != files.end(); ++it) {
            const String &key = *it;
            out.append(key);
            bool ok;
            switch (mode) {
            case All:
                ok = true;
                break;
            case Regex:
                ok = Rct::contains(out, mRegex);
                break;
            case FilePath:
            case Pattern:
                if (!preferExact) {
                    ok = out.contains(mPattern, cs);
                } else {
                    const int outSize = out.size();
                    const bool exact = (outSize > patternSize && out.endsWith(mPattern) && out.at(outSize - (patternSize + 1)) == '/');
                    if (exact) {
                        ok = true;
                        if (!foundExact) {
                            matches.clear();
                            foundExact = true;
                        }
                    } else {
                        ok = !foundExact && out.contains(mPattern, cs);
                    }
                }
                if (!ok && mode == FilePath) {
                    Path p(out);
                    if (!absolutePath)
                        p.prepend(srcRoot);
                    p.resolve();
                    if (p == mPattern)
                        ok = true;
                }
                break;
            }
            if (ok) {
                ret = 0;

                Path matched = out;
                if (absolutePath)
                    matched.resolve();
                if (preferExact && !foundExact) {
                    matches.append(matched);
                } else {
                    if (!writeFile(matched))
                        return 1;
                }
            }
            out.chop(key.size());
        }
        out.chop(dir.size() - srcRoot.size());
        ++dirit;
    }
    for (List<String>::const_iterator it = matches.begin(); it != matches.end(); ++it) {
        if (!writeFile(*it)) {
            return 1;
        }
    }
    if (queryFlags() & QueryMessage::Elisp && !firstElisp && !write(")", DontQuote))
        return 1;
    return ret;
}
	//---------------------------------------------------------------------
	void GLSLESProgramManagerCommon::extractConstantDefs(const String& src,
		GpuNamedConstants& defs, const String& filename)
	{
		// Parse the output string and collect all uniforms
		// NOTE this relies on the source already having been preprocessed
		// which is done in GLSLESProgram::loadFromSource
		String line;
		String::size_type currPos = src.find("uniform");
		while (currPos != String::npos)
		{
			GpuConstantDefinition def;
			String paramName;

			// Now check for using the word 'uniform' in a larger string & ignore
			bool inLargerString = false;
			if (currPos != 0)
			{
				char prev = src.at(currPos - 1);
				if (prev != ' ' && prev != '\t' && prev != '\r' && prev != '\n'
					&& prev != ';')
					inLargerString = true;
			}
			if (!inLargerString && currPos + 7 < src.size())
			{
				char next = src.at(currPos + 7);
				if (next != ' ' && next != '\t' && next != '\r' && next != '\n')
					inLargerString = true;
			}

			// skip 'uniform'
			currPos += 7;

			if (!inLargerString)
			{
                String::size_type endPos;
                String typeString;
                GpuSharedParametersPtr blockSharedParams;

                // Check for a type. If there is one, then the semicolon is missing
                // otherwise treat as if it is a uniform block
				String::size_type lineEndPos = src.find_first_of("\n\r", currPos);
				line = src.substr(currPos, lineEndPos - currPos);
                StringVector parts = StringUtil::split(line, " \t");

                // Skip over precision keywords
                if(StringUtil::match((parts.front()), "lowp") ||
                   StringUtil::match((parts.front()), "mediump") ||
                   StringUtil::match((parts.front()), "highp"))
                    typeString = parts[1];
                else
                    typeString = parts[0];

                StringToEnumMap::iterator typei = mTypeEnumMap.find(typeString);
                if (typei == mTypeEnumMap.end())
                {
                    // Gobble up the external name
                    String externalName = parts.front();

                    // Now there should be an opening brace
                    String::size_type openBracePos = src.find("{", currPos);
                    if (openBracePos != String::npos)
                    {
                        currPos = openBracePos + 1;
                    }
                    else
                    {
                        LogManager::getSingleton().logMessage("Missing opening brace in GLSL Uniform Block in file "
                                                              + filename);
                        break;
                    }

                    // First we need to find the internal name for the uniform block
                    String::size_type endBracePos = src.find("}", currPos);

                    // Find terminating semicolon
                    currPos = endBracePos + 1;
                    endPos = src.find(";", currPos);
                    if (endPos == String::npos)
                    {
                        // problem, missing semicolon, abort
                        break;
                    }
                }
                else
                {
                    // find terminating semicolon
                    endPos = src.find(";", currPos);
                    if (endPos == String::npos)
                    {
                        // problem, missing semicolon, abort
                        break;
                    }
                    
                    parseIndividualConstant(src, defs, currPos, filename, blockSharedParams);
                }
                line = src.substr(currPos, endPos - currPos);
			} // not commented or a larger symbol

			// Find next one
			currPos = src.find("uniform", currPos);
		}
		
	}
Example #13
0
//-----------------------------------------------------------------------
size_t FileInStream::readLine(char* buf, size_t maxCount, const String& delim)
{
    if (delim.empty())
    {
        U2_EXCEPT(Exception::ERR_INVALIDPARAMS, "No delimiter provided",
                  "FileStreamDataStream::readLine");
    }
    if (delim.size() > 1)
    {
        LogManager::getSingleton().logMessage(
            "WARNING: FileStreamDataStream::readLine - using only first delimeter");
    }
    // Deal with both Unix & Windows LFs
    bool trimCR = false;
    if (delim.at(0) == '\n')
    {
        trimCR = true;
    }
    // maxCount + 1 since count excludes terminator in getline
    m_pFInStream->getline(buf, static_cast<std::streamsize>(maxCount + 1), delim.at(0));
    size_t ret = (size_t)m_pFInStream->gcount();
    // three options
    // 1) we had an eof before we read a whole line
    // 2) we ran out of buffer space
    // 3) we read a whole line - in this case the delim character is taken from the stream but not written in the buffer so the read data is of length ret-1 and thus ends at index ret-2
    // in all cases the buffer will be null terminated for us

    if (m_pFInStream->eof())
    {
        // no problem
    }
    else if (m_pFInStream->fail())
    {
        // Did we fail because of maxCount hit? No - no terminating character
        // in included in the count in this case
        if (ret == maxCount)
        {
            // clear failbit for next time
            m_pFInStream->clear();
        }
        else
        {
            U2_EXCEPT(Exception::ERR_INTERNAL_ERROR,
                      "Streaming error occurred",
                      "FileStreamDataStream::readLine");
        }
    }
    else
    {
        // we need to adjust ret because we want to use it as a
        // pointer to the terminating null character and it is
        // currently the length of the data read from the stream
        // i.e. 1 more than the length of the data in the buffer and
        // hence 1 more than the _index_ of the NULL character
        --ret;
    }

    // trim off CR if we found CR/LF
    if (trimCR && buf[ret - 1] == '\r')
    {
        --ret;
        buf[ret] = '\0';
    }
    return ret;
}
Example #14
0
CommandLine parseCommandLine(int argc, const char** argv)
{
    // Parse command line ...

    CommandLine cmdLine;
    cmdLine.commandName = argv[0];

    int idx = 1; // Current argv-index for the following for-loops to start with
    // Determine number of global arguments
    int numGlobalArgs = 0;
    for (int i = idx; i < argc; ++i)
    {
        String arg = argv[i];
        if (!arg.empty() && arg.at(0) != '-')
        {
            // This item has to be the toolname
            cmdLine.toolName = arg;

            // We are done with counting
            numGlobalArgs = i - 1;

            idx = i + 1;

            break;
        }
        else if (i == argc - 1)
        {
            // There is no toolname
            numGlobalArgs = i;
        }
    }

    cmdLine.globalArgc = numGlobalArgs;
    cmdLine.globalArgv = numGlobalArgs > 0 ? argv + 1 : NULL;

    if (!cmdLine.toolName.empty())
    {
        // determine number of tool arguments
        int numToolArgs = 0;
        for (int i = idx; i < argc; ++i)
        {
            String arg = argv[i];
            if (!arg.empty() && arg.at(0) != '-')
            {
                // this item is the infile
                cmdLine.inFileNames.push_back(arg);

                // We are done with counting
                numToolArgs = i - numGlobalArgs - 2;

                idx = i + 1;

                break;
            }
        }

        cmdLine.toolArgc = numToolArgs;
        cmdLine.toolArgv = numToolArgs > 0 ? argv + numGlobalArgs + 2 : NULL;

        // Are there further input files?
        for (int i = idx; i < argc; ++i)
        {
            String arg = argv[i];
            if (arg == "--")
            {
                // No more input files
                idx = i + 1;
                break;
            }
            else
            {
                // this item is the infile
                cmdLine.inFileNames.push_back(arg);
            }
        }


        // If there are elements left in the argv, these have to be output files
        for (int i = idx; i < argc; ++i)
        {
            String arg = argv[i];
            cmdLine.outFileNames.push_back(arg);
        }
    }

    return cmdLine;
}