void load_database_contexts(Context_Map* context_map)
{
    int prefix_mask {};
    
    std::ifstream buf;
    buf.open(DBCONFIG_FILE);
    assert(buf.is_open());

    std::string line {};
    
    while (!buf.eof())
    {
        getline(buf,line);
        if (ignore_line(line)) continue;
        else if (str_contains(line,'@'))
        {
            int port {};
            std::string host {};
            int db_num {};
            
            // Complete at 00000111 (7)
            // One bit is set each time one of the above is found.
            // This allows for any number of newlines or comments.
            uint8_t completion {};
            Prefix p {match_prefix(prefix_mask, line)};
            while ((completion != 7) && !buf.eof())
            {
                getline(buf,line);
                if (ignore_line(line)) continue;
                else if (str_contains(line,"port"))
                {
                    port = extract_integer(line);
                    completion |= 1;
                }
                else if (str_contains(line, "number"))
                {
                    db_num = extract_integer(line);
                    completion |= 2;
                }
                else if (str_contains(line, "host"))
                {
                    host = extract_host(line);
                    completion |= 4;
                }
            }
            assert(completion==7);
            Redis::Context* c = new Redis::Context();
            c->port = port;
            c->host = host;
            c->db_num = db_num;
            context_map->set(p,c);
            assert(context_map->get(p));
        }
    }
    buf.close();
    assert(prefix_mask >= max_prefix_mask);
    assert(context_map);
}
Example #2
0
static bool ignoreShaderLog(const char* buf)
{
    // damnit ATI driver
    static string kNoErrors = "No errors.\n";
    return (buf == kNoErrors ||
            str_contains(buf, "Validation successful") ||
            str_contains(buf, "successfully compiled") ||
            str_contains(buf, "shader(s) linked."));
}
Example #3
0
void test_css_util_stringx()
{
	char *str;
	assert(1 == str_contains("hello word","wor"));
	assert(0 == str_contains("hello word","worw"));
	assert(2 == str_index_of("hello word","ll"));
	assert(-1 == str_index_of("hello word","lldd"));

	COPY_STR(str,"2abc123");
	str_to_upper(str);
	assert(strcmp(str,"2ABC123") == 0);
	str_to_lower(str);
	assert(strcmp(str,"2abc123") == 0);
}
Prefix match_prefix (int& prefix_mask, const std::string& prefix)
{
    if (str_contains(prefix, "widget"))
    {
        prefix_mask |= (int) Prefix::widget;
        return Prefix::widget;
    }
    else if (str_contains(prefix, "data"))
    {
        prefix_mask |= (int) Prefix::data;
        return Prefix::data;
    }
    else if (str_contains(prefix, "user"))
    {
        prefix_mask |= (int) Prefix::user;
        return Prefix::user;
    }
    else if (str_contains(prefix,"group"))
    {
        prefix_mask |= (int) Prefix::group;
        return Prefix::group;
    }
    else if (str_contains(prefix,"template"))
    {
        prefix_mask |= (int) Prefix::template_;
        return Prefix::template_;
    }
    else if (str_contains(prefix,"perspective"))
    {
        prefix_mask |= (int) Prefix::perspective;
        return Prefix::perspective;
    }
    else if (str_contains(prefix,"validator"))
    {
        prefix_mask |= (int) Prefix::validator;
        return Prefix::validator;
    }
    else if (str_contains(prefix,"policy"))
    {
        prefix_mask |= (int) Prefix::policy;
        return Prefix::policy;
    }
    else if (str_contains(prefix,"meta"))
    {
        prefix_mask |= (int) Prefix::meta;
        return Prefix::meta;
    }
    else return Prefix::__NONE__;
}
Example #5
0
File: ace_str.c Project: idx0/ace
void str_ltrim_ex(char** sz, const char* pattern)
{
	assert(sz);
	assert(*sz);

	char* s = *sz;

	while (*s) {
		if (str_contains(pattern, *s)) {
			s++;
			(*sz)++;
		}
		else { break; }
	}
}
Example #6
0
std::string Dynamic_Server::get_template_name(const std::string& declaration)
{
    const static std::string using_ {Mogu_Syntax::preposition.str};
    const static std::string template_ {Mogu_Syntax::template_.str};

    if (!str_contains(declaration, using_))
        return "";
    // Get the index of "template"
    size_t tmpl_index {declaration.find(template_)};

    if (tmpl_index==std::string::npos) return "";

    size_t tmpl_name_start = tmpl_index+2;
    std::string sub = declaration.substr(tmpl_name_start);
    return trim(sub);

}
Example #7
0
File: ace_str.c Project: idx0/ace
void str_rtrim_ex(char* sz, const char* pattern)
{
	char* s = sz;
	char* last = NULL;

	assert(sz);

	while (*s) {
		if (!str_contains(pattern, *s)) {
			/* keep track of the last non-trimmable character */
			last = s;
		}
		s++;
	}

	if (last) {
		/* move the null character */
		last++;
		*last = 0;
	} else {
		/* string was all trimmable */
		*sz = 0;
	}
}
inline bool ignore_line(const std::string& line)
{
    return (str_contains(line,'#') || line.empty());
}