Example #1
0
String String::join(String path, String fname)
{
	String joined;
	#ifdef _WIN32
		if (path.size() == 0 || fname.size() == 0)
			joined = path + "\\" + fname;
		else
		{
			char end = path.at(path.length() - 1);
			char begin = fname.at(0);
			if (String(&end) == "/" || String(&begin) == "/")
				joined = path + fname;
			else
				joined = path + "\\" + fname;
		}
	#else
		if (path.size() == 0 || fname.size() == 0)
			joined = path + "/" + fname;
		else
		{
			char end = path.at(path.length() - 1);
			char begin = fname.at(0);
			if (String(&end) == "/" || String(&begin) == "/")
				joined = path + fname;
			else
				joined = path + "/" + fname;
		}
	#endif
	
	return joined;
}
 String SearchQuery::GetMin(String s) {
     if (s.length() < 3) return "";
     if (s.at(0) == '.' && s.at(1) == '.') return "";
     int i = s.find("..");
     if (i == std::string::npos) return "";
     return s.substr(0, i);
 }
Example #3
0
String String::toUpper()
{
	String text = getString();
	for (int i = 0; i < _size; i++)
	{
		text.at(i) = toupper(text.at(i));
	}
	return text;
}
    void AbstractFinder::AddSql(String Col, String Pattern, std::stringstream& Sql) {
        if (Pattern.length() == 0) return;

        if (IsRegex(Pattern)) {
#ifndef WIN32
            Sql << " AND " << Col << " regexp ?";
#else
            for (int i = 0; i < Pattern.length(); i++) {
                if (Pattern.at(i) == '?') Pattern.at(i) = '_';
                else if (Pattern.at(i) == '*') Pattern.at(i) = '%';
            }
            Sql << " AND " << Col << " LIKE ?";
#endif
            Params.push_back(Pattern);
            return;
        }

        String buf;
        std::vector<String> tokens;
        std::vector<String> tokens2;
        std::stringstream ss(Pattern);
        while (ss >> buf) tokens.push_back(buf);

        if (tokens.size() == 0) {
            Sql << " AND " << Col << " LIKE ?";
            Params.push_back("%" + Pattern + "%");
            return;
        }

        bool b = false;
        for (int i = 0; i < tokens.size(); i++) {
            Sql << (i == 0 ? " AND (" : "");

            for (int j = 0; j < tokens.at(i).length(); j++) {
                if (tokens.at(i).at(j) == '+') tokens.at(i).at(j) = ' ';
            }

            ss.clear();
            ss.str("");
            ss << tokens.at(i);

            tokens2.clear();
            while (ss >> buf) tokens2.push_back(buf);

            if (b && tokens2.size() > 0) Sql << " OR ";
            if (tokens2.size() > 1) Sql << "(";
            for (int j = 0; j < tokens2.size(); j++) {
                if (j != 0) Sql << " AND ";
                Sql << Col << " LIKE ?";
                Params.push_back("%" + tokens2.at(j) + "%");
                b = true;
            }
            if (tokens2.size() > 1) Sql << ")";
        }
        if (!b) Sql << "0)";
        else Sql << ")";
    }
Example #5
0
void Test_M2MString::test_at()
{
    String s("name");
    const String s1("yeb");

    CHECK(s.at(1) == 'a');
    CHECK(s.at(14) == '\0');
    CHECK(s1.at(1) == 'e');
    CHECK(s1.at(31) == '\0');
}
    DirectoryCopier::DirectoryCopier(String SrcParentDir, String DestDir) {
        this->SrcParentDir = SrcParentDir;
        this->DestDir = DestDir;

        if (DestDir.at(DestDir.length() - 1) != '/') {
            this->DestDir.append("/");
        }
        if (SrcParentDir.at(SrcParentDir.length() - 1) != '/') {
            this->SrcParentDir.append("/");
        }
    }
Example #7
0
String Location::context(Flags<ToStringFlag> flags, Hash<Path, String> *cache) const
{
    String copy;
    String *code = 0;
    const Path p = path();
    if (cache) {
        String &ref = (*cache)[p];
        if (ref.isEmpty()) {
            ref = p.readAll();
        }
        code = &ref;
    } else {
        copy = p.readAll();
        code = &copy;
    }

    String ret;
    if (!code->isEmpty()) {
        unsigned int l = line();
        if (!l)
            return String();
        const char *ch = code->constData();
        while (--l) {
            ch = strchr(ch, '\n');
            if (!ch)
                return String();
            ++ch;
        }
        const char *end = strchr(ch, '\n');
        if (!end)
            return String();

        ret.assign(ch, end - ch);
        // error() << "foobar" << ret << bool(flags & NoColor);
        if (!(flags & NoColor)) {
            const size_t col = column() - 1;
            if (col + 1 < ret.size()) {
                size_t last = col;
                if (ret.at(last) == '~')
                    ++last;
                while (ret.size() > last && (isalnum(ret.at(last)) || ret.at(last) == '_'))
                    ++last;
                static const char *color = "\x1b[32;1m"; // dark yellow
                static const char *resetColor = "\x1b[0;0m";
                // error() << "foobar"<< end << col << ret.size();
                ret.insert(last, resetColor);
                ret.insert(col, color);
            }
            // printf("[%s]\n", ret.constData());
        }
    }
    return ret;
}
Example #8
0
bool endsWithHelper(idx_t from, const String& left, const String& right) {
    if (from < right.length()) {
        return false;
    }
    suint count = 0;
    for (idx_t i = 0; i < right.length(); i++) {
        if (left.at(from - i) == right.at(-i-1)) {
            count++;
            if(count == right.length()) return true;
        } else break;
    }
    return false;
}
Example #9
0
SYLPH_BEGIN_NAMESPACE

bool startsWithHelper(idx_t from, const String& left, const String& right) {
    if (left.length() - from < right.length()) return false;
    suint count = 0;
    for (idx_t i = 0; i < right.length(); i++) {
        if (left.at(i + from) == right.at(i)) {
            count++;
            if(count == right.length()) return true;
        }
        else break;
    }
    return false;
}
Example #10
0
void ConfigFile::Load()
{
    std::ifstream   inFile( mFileName.c_str() );

    if( inFile.fail() )
    {
        inFile.close();
        throw FileNotFoundException( mFileName, Here );
    }

    String              sectionName;
    String              nextWord;
    char                buffer[512];
    std::stringstream   lineStream;
    
    inFile.getline(buffer, 512);
    while( inFile.good() )
    {        
        lineStream.clear();
        lineStream.str(buffer);
                
        // Read section name ("[Section Name]").
        lineStream >> sectionName;
        while( !lineStream.fail() )
        {
            lineStream >> nextWord;
            if( !lineStream.fail() )
            {
                sectionName += " ";
                sectionName += nextWord;
            }
        }        
        
        // Find opening and closing bracket (must be at start and end of section name).
        if( sectionName.at(0) != '[' || sectionName.at( sectionName.size() -1 ) != ']' )
        {
            inFile.close();
            throw InvalidConfigFileException( mFileName, Here );
        }

        // Extract the section name from the string (remove "[]")
        sectionName = sectionName.substr( 1, sectionName.length() - 2 );

        // Load this section.
        (*this)[sectionName].Load(inFile);

        // Read another section...
        inFile.getline(buffer, 512);
    }
}
Example #11
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 #12
0
File: URI.cpp Project: 4nkh/rhodes
/*static*/ void URI::urlEscapeSymbols(const String& fullPath, String& strRes)
{
    int len = fullPath.length();

    char c;
    boolean bFound = false;
    for  (int index=0; index < len ; index++)
    {
        c = fullPath.at(index);
        if ( (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
             c == '_' || c == '.') 
        {
            if ( bFound ) 
                strRes += c;
        }else 
        {
            if ( !bFound )
            {
                strRes += fullPath.substr(0,index);
                bFound = true;
            }
            strRes += '_';
        }
    }

    if ( !bFound )
        strRes += fullPath;
}
Example #13
0
int CAppManager::removeOldRhoBundle (void)
{
	String root = rho_native_rhopath();
	root.at(root.length()-1) = '\\';

	if (!RemoveFolder(root + "apps")) {
		LOG(ERROR) + "Failed to remove" + "\"" + (root + "apps") + "\"";
		return RRB_REMOVEOLD_ERR;
	}

#if defined(APP_BUILD_CAPABILITY_SYMBOL)
	const char *rhopath = rho_native_rhopath();
	const char *runtimepath = rho_native_reruntimepath();
	int rhopath_len = strlen(rhopath);
	int runtimepath_len = strlen(runtimepath);
	if ((rhopath_len > 0) && (rhopath_len == runtimepath_len) && (_strnicmp(rhopath, runtimepath, rhopath_len)==0)) {
#endif
		if (!RemoveFolder(root + "lib")) {
			LOG(ERROR) + "Failed to remove" + "\"" + (root + "lib	") + "\"";
			return RRB_REMOVEOLD_ERR;
		}
#if defined(APP_BUILD_CAPABILITY_SYMBOL)
	}
#endif
	
	return RRB_NONE_ERR;
}
void JsonWriter::describeValueConst(const String& ref)
{
        String stringValue = ref;

        // escape forbidden control characters according to json.org
        size_t foundPosition = stringValue.find('\\', 0);
        while (foundPosition != std::string::npos) {
                if (foundPosition+1 >= stringValue.length() ||
                        (stringValue.at(foundPosition +1) != '\\' &&
                         stringValue.at(foundPosition +1) !='/')) {

                        stringValue.replace(foundPosition, 1, "\\\\");
                }
                foundPosition = stringValue.find('\\', foundPosition+2);
        }

        nw::utils::replaceAll(stringValue, "\"", "\\\"");
        //nw::utils::replaceAll(stringValue, '\/', "\\/"); //valid?
        nw::utils::replaceAll(stringValue, '\b', "\\b");
        nw::utils::replaceAll(stringValue, '\f', "\\f");
        nw::utils::replaceAll(stringValue, '\n', "\\n");
        nw::utils::replaceAll(stringValue, '\r', "\\r");
        nw::utils::replaceAll(stringValue, '\t', "\\t");
        //resolves to unicode and unicode is a valid char. \\u is caught by \\ rep
        //nw::utils::replaceAll(stringValue, '\u', "\\u");

        selectedTag->setValue(stringValue);
        static_cast<JsonTag*>(selectedTag)->setType(JsonType::String);
}
Example #15
0
Theme::Theme(String path)
    : path_(path),
      name_(path->fileName()),
      paletteByScope_(PaletteByScope::create())
{
    Ref<Dir> dir = Dir::open(path);
    String name;
    while (dir->read(&name)) {
        if (name == "." || name == "..") continue;
        if (!(name->count() > 0 && ('a' <= name->at(0) && name->at(0) <= 'z'))) continue;
        Ref<Palette> palette = Palette::load(path + "/" + name);
        paletteByScope_->insert(palette->scope(), palette);
    }
    if (!paletteByScope_->lookup(Palette::defaultScope(), &defaultPalette_))
        throw UsageError(Format("Palette \"default\" missing in theme \"%%\"") << path);
}
Example #16
0
bool QueryJob::write(const String &out, Flags<WriteFlag> flags)
{
    if ((mJobFlags & WriteUnfiltered) || (flags & Unfiltered) || filter(out)) {
        if ((mJobFlags & QuoteOutput) && !(flags & DontQuote)) {
            String o((out.size() * 2) + 2, '"');
            char *ch = o.data() + 1;
            int l = 2;
            for (size_t i=0; i<out.size(); ++i) {
                const char c = out.at(i);
                switch (c) {
                case '"':
                case '\\':
                    *(ch + 1) = c;
                    *ch = '\\';
                    ch += 2;
                    l += 2;
                    break;
                default:
                    ++l;
                    *ch++ = c;
                    break;
                }
            }
            o.truncate(l);
            return writeRaw(o, flags);
        } else {
            return writeRaw(out, flags);
        }
    }
    return true;
}
Example #17
0
	void PathUtil::toUnixPath(String& path) {
		size_t len = path.length();
		for (size_t i=0; i<len; i++) {
			if (path[i] == L'\\')
				path.at(i) = L'/';
		}
	}
Example #18
0
	void PathUtil::convertSlash(String& path, char slash) {
		size_t len = path.length();
		for (size_t i=0; i<len; i++) {
			if (PathUtil::isDirectoryLetter(path[i]))
				path.at(i) = slash;
		}
	}
Example #19
0
bool QueryJob::write(const String &out, Flags<WriteFlag> flags)
{
    if ((mJobFlags & WriteUnfiltered) || (flags & Unfiltered) || filter(out)) {
        if ((mJobFlags & QuoteOutput) && !(flags & DontQuote)) {
            String o((out.size() * 2) + 2, '"');
            char *ch = o.data() + 1;
            int l = 2;
            for (int i=0; i<out.size(); ++i) {
                const char c = out.at(i);
                if (c == '"') {
                    *ch = '\\';
                    ch += 2;
                    l += 2;
                } else {
                    ++l;
                    *ch++ = c;
                }
            }
            o.truncate(l);
            return writeRaw(o, flags);
        } else {
            return writeRaw(out, flags);
        }
    }
    return true;
}
Example #20
0
bool WebItemCollection::Create(const String& resource, ref<WebItem> wi, bool overwrite) {
	// Require put permission to create new collections
	if(!GetPermissions().IsSet(WebItem::PermissionPut)) {
		return false;
	}

	if(!GetPermissions().IsSet(WebItem::PermissionPropertyWrite)) {
		return false;
	}
	
	String collectionName = resource;
	if(collectionName.length()<1) {
		return false;
	}
	
	if(collectionName.at(0)==L'/') {
		collectionName = collectionName.substr(1);
		if(collectionName.length()<1) {
			return false;
		}
	}
	
	String::const_iterator firstSlash = std::find(collectionName.begin(), collectionName.end(), L'/');
	if(firstSlash!=collectionName.end()) {
		// This is not the final resource name (yet); recurse
		String restOfPath;
		ref<WebItem> wi = GetNextByPath(collectionName, restOfPath);
		if(wi && wi!=ref<WebItem>(this)) {
			return wi->Create(restOfPath, wi, overwrite);
		}
	}
	else {
		// The resource to be put onto is right under me; see if it exists already
		ThreadLock lock(&_lock);
		std::deque< ref<WebItem> >::iterator it = _children.begin();
		while(it!=_children.end()) {
			ref<WebItem> wi = *it;
			if(wi) {
				if(wi->GetName()==collectionName) {
					if(overwrite) {
						_children.erase(it);
						_children.push_back(wi);
						return true;
					}
					else {
						return false;
					}
				}
			}
			++it;
		}

		wi->Rename(collectionName);
		_children.push_back(wi);
		return true;
	}
	
	return false;
}
Example #21
0
    String String::toLower(const String& other)
    {
        String result;

        for(unsigned int i = 0; i < other.size(); ++i)
            result.append(toLower(other.at(i)));

        return result;
    }
Example #22
0
    size_t String::findLast(const String & str) const
    {


        for(int i = size() - str.size(); i >= 0; i--)
        {
            if(mstr.at(i) == str.at(0))
            {
                for(unsigned int j = 1; j < str.size(); j++)
                {
                    if(j == str.size() - 1 && mstr.at(j) == str.at(j))
                        return i;
                }
            }
        }

        return size();
    }
Example #23
0
    size_t String::findFirst(const String & str, size_t from) const
    {


        for(unsigned int i = from; i < size() && size() - i < str.size(); i++)
        {
            if(mstr.at(i) == str.at(0))
            {
                for(unsigned int j = 1; j < str.size(); j++)
                {
                    if(j == str.size() - 1 && mstr.at(j) == str.at(j))
                        return i;
                }
            }
        }

        return size();
    }
 void DirectoryScanner::Scan(String DbDir, String FsDir, bool Flat, bool insDir, ScanProgress* pProgress) {
     dmsg(2,("DirectoryScanner: Scan(DbDir=%s,FsDir=%s,Flat=%d,insDir=%d)\n", DbDir.c_str(), FsDir.c_str(), Flat, insDir));
     if (DbDir.empty() || FsDir.empty()) throw Exception("Directory expected");
     
     this->DbDir = DbDir;
     this->FsDir = FsDir;
     this->insDir = insDir;
     if (DbDir.at(DbDir.length() - 1) != '/') {
         this->DbDir.append("/");
     }
     if (FsDir.at(FsDir.length() - 1) != File::DirSeparator) {
         this->FsDir.push_back(File::DirSeparator);
     }
     this->Flat = Flat;
     this->pProgress = pProgress;
     
     File::WalkDirectoryTree(FsDir, this);
 }
Example #25
0
static bool containsOnlyASCIIWithNoUppercase(const String& domain)
{
    for (unsigned i = 0; i < domain.length(); ++i) {
        UChar c = domain.at(i);
        if (!isASCII(c) || isASCIIUpper(c))
            return false;
    }
    return true;
}
void test2()
{
    String greet("Hello");
    char ch1 = greet.at(0); // в char ch1 = greet.at(0) будет вызвана не const версия метода at
    printf("%c\n", ch1);

    String const const_greet("Hello, Const!");
    char const &ch2 = const_greet.at(0); // в char const & ch2 = const_greet.at(0) будет вызвана const версия метода at
    printf("%c\n", ch2);
}
Example #27
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 #28
0
    void String::append(const String & c)
    {


        if(c.size() > 0)
        {
            for(unsigned int i = 0; i < c.size(); i++)
                append(c.at(i));
        }
        assertFinal();
    }
Example #29
0
	static void PrintLongDescription(std::ostream& out, const String& description)
	{
		uint start = 0;
		uint end = 0;
		uint offset = 0;

		do
		{
			// Jump to the next separator
			offset = description.find_first_of(" .\r\n\t", offset);

			// No separator, aborting
			if (String::npos == offset)
				break;

			if (offset - start < LengthLimit)
			{
				if ('\n' == description.at(offset))
				{
					out.write(description.c_str() + start, (std::streamsize)(offset - start));
					out << '\n';
					if (Decal)
						out.write(YUNI_GETOPT_HELPUSAGE_30CHAR, 30);

					start = offset + 1;
					end = offset + 1;
				}
				else
					end = offset;
			}
			else
			{
				if (0 == end)
					end = offset;

				out.write(description.c_str() + start, (std::streamsize)(end - start));
				out << '\n';

				if (Decal)
					out.write(YUNI_GETOPT_HELPUSAGE_30CHAR, 30);

				start = end + 1;
				end = offset + 1;
			}

			++offset;
		}
		while (true);

		// Display the remaining piece of string
		if (start < description.size())
			out << (description.c_str() + start);
	}
Example #30
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;

	}