Ejemplo n.º 1
0
Properties parseToPropertiesMap(std::istream& file)
{
    Properties properties;

    std::string line;
    while (safeGetline(file, line)) {
        line = stripComments(line);

        boost::char_separator<char> sep("=");
        boost::tokenizer<boost::char_separator<char>> tok(line, sep);

        auto word = tok.begin();
        if (word == tok.end()) {
            continue;
        }

        std::string key = stripWhitespace(*word);
        if (key == "") {
            continue;
        }

        if (++word == tok.end())
        {
            continue;
        }
        std::string value = stripWhitespace(*word);

        properties[key] = value;
    }

    return properties;
}
Ejemplo n.º 2
0
void processGoalie(Game* game, League* league, std::string rawGoalieString, bool done){
	/*
	Initialize values to their default states
	*/
	std::string gID = game->id;
	std::string tID="null";
	int player = 0;
	int shots = 0;
	int goals = 0;
	int seconds = 0;

	player = std::stoi(split(split(rawGoalieString, "playerid=")[1], "&")[0]);

	std::vector<std::string> items = split(rawGoalieString, "</td>");
	items.erase(items.begin());

	for(int i = 0; i < items.size(); i++){
		items[i] = extract(items[i]+"</td>", "td");
	}
	if(stripWhitespace(items[0]) == "")
		return;
	seconds = std::stoi(stripWhitespace(items[0]));
	shots = std::stoi(stripWhitespace(items[1]));
	goals = shots - std::stoi(stripWhitespace(items[2]));

	tID = league->getPlayer(player)->teamID;

	league->setGoaliePerformance(gID, tID, player, seconds, goals, shots);

	if(done){
		Player* p = league->getPlayer(player);
		p->gamesPlayed++;
		p->shots += shots;
		p->goalsAgainst += goals;
		p->minutesPlayed += seconds;
		p->saves += shots-goals;
		if(p->gamesPlayed == 0){
			p->goalsAgainstAverage = 0;
		}else{
			p->goalsAgainstAverage = p->goalsAgainst*1.0/p->gamesPlayed;
		}
		if(p->shots == 0){
			p->savePercentage = 0;
		}else{
			p->savePercentage = p->saves*1.0/p->shots;
		}
		std::cout<<"Updating Goalie \n";
		db_updatePlayer(p, league);
		std::cout<<"Successfully finished updating goalie\n";
	}

}
Ejemplo n.º 3
0
std::size_t ShaderParser::parseDepthSettings(std::size_t startIndex)
{
    std::string resultingSource;
    std::size_t endIndex = parseSourceFrom(startIndex, resultingSource);

    resultingSource = stripWhitespace(resultingSource);
    compileSettingParameter(myDepthSettings.enabled, resultingSource, "enabled");
    compileSettingsParameter(myDepthSettings.function, resultingSource, "function");

    return endIndex;
}
Ejemplo n.º 4
0
std::size_t ShaderParser::parseBlendSettings(std::size_t startIndex)
{
    std::string resultingSource;
    std::size_t endIndex = parseSourceFrom(startIndex, resultingSource);

    resultingSource = stripWhitespace(resultingSource);
    compileSettingParameter(myBlendSettings.enabled, resultingSource, "enabled");
    compileSettingsParameter(myBlendSettings.sourceFactor, resultingSource, "sourceFactor");
    compileSettingsParameter(myBlendSettings.destinationFactor, resultingSource, "destinationFactor");
    compileSettingsParameter(myBlendSettings.function, resultingSource, "function");

    return endIndex;
}
Ejemplo n.º 5
0
/* Returns whether a sequence of chars is empty or not */
LATBool isSequenceEmpty(char *input) {
    
    char *tmp = stripWhitespace(input);
    
    while(*tmp) {
        
        if(*tmp != '\n' && *tmp != '\r' && *tmp != '\t') {
            
            return false;
        }
        tmp++;
    }
    return true;
}
Ejemplo n.º 6
0
static int
testJSONSnippet( const char * benc_str,
                 const char * expected )
{
    tr_benc top;
    char *  serialized;

    tr_bencLoad( benc_str, strlen( benc_str ), &top, NULL );
    serialized = tr_bencSaveAsJSON( &top, NULL );
    stripWhitespace( serialized );
#if 0
    fprintf( stderr, "benc: %s\n", benc_str );
    fprintf( stderr, "json: %s\n", serialized );
    fprintf( stderr, "want: %s\n", expected );
#endif
    check( !strcmp( serialized, expected ) );
    tr_free( serialized );
    tr_bencFree( &top );
    return 0;
}
Ejemplo n.º 7
0
/*	func:	inputString
	in:		prompt (const char*) - prompt to display
			size (size_t) - max size of input string
				INCLUDING null terminator
	out:	pointer to input string (char)
	desc:	prompts user, then uses fgets() to input a string;
			truncates and discards any input after size chars
*/
char *inputString(const char *prompt, int size)
{
	char *in = malloc(size);
	int i = 0;
	char c = 0;
	
	printf("%s", prompt);
	fgets(in, size, stdin);	// get a line
	
	for (i = 0; i < size; i++)	// look for newline (if not found, we've overrun)
		if (in[i] == '\n')
			c = !(in[i] = 0);	// using c as temp flag to skip getchar() if newline found
	
	// if we didn't find newline, flush overrun chars
	if (c == 0) while ((c = getchar()) != '\n' && c != 0);
	
	// remove whitespace from beginning and end of string
	stripWhitespace(in);
	
	return in;
}
Ejemplo n.º 8
0
static int
testJSONSnippet( const char * benc_str,
                 const char * expected )
{
    tr_benc top;
    char * serialized;
    struct evbuffer * buf;

    tr_bencLoad( benc_str, strlen( benc_str ), &top, NULL );
    buf = tr_bencToBuf( &top, TR_FMT_JSON );
    serialized = (char*) evbuffer_pullup( buf, -1 );
    stripWhitespace( serialized );
#if 0
    fprintf( stderr, "benc: %s\n", benc_str );
    fprintf( stderr, "json: %s\n", serialized );
    fprintf( stderr, "want: %s\n", expected );
#endif
    check_streq (expected, serialized);
    tr_bencFree( &top );
    evbuffer_free( buf );
    return 0;
}
Ejemplo n.º 9
0
void
RuleBasedNumberFormat::init(const UnicodeString& rules, LocalizationInfo* localizationInfos,
                            UParseError& pErr, UErrorCode& status)
{
    // TODO: implement UParseError
    uprv_memset(&pErr, 0, sizeof(UParseError));
    // Note: this can leave ruleSets == NULL, so remaining code should check
    if (U_FAILURE(status)) {
        return;
    }

    this->localizations = localizationInfos == NULL ? NULL : localizationInfos->ref();

    UnicodeString description(rules);
    if (!description.length()) {
        status = U_MEMORY_ALLOCATION_ERROR;
        return;
    }

    // start by stripping the trailing whitespace from all the rules
    // (this is all the whitespace follwing each semicolon in the
    // description).  This allows us to look for rule-set boundaries
    // by searching for ";%" without having to worry about whitespace
    // between the ; and the %
    stripWhitespace(description);

    // check to see if there's a set of lenient-parse rules.  If there
    // is, pull them out into our temporary holding place for them,
    // and delete them from the description before the real desciption-
    // parsing code sees them
    int32_t lp = description.indexOf(gLenientParse, -1, 0);
    if (lp != -1) {
        // we've got to make sure we're not in the middle of a rule
        // (where "%%lenient-parse" would actually get treated as
        // rule text)
        if (lp == 0 || description.charAt(lp - 1) == gSemiColon) {
            // locate the beginning and end of the actual collation
            // rules (there may be whitespace between the name and
            // the first token in the description)
            int lpEnd = description.indexOf(gSemiPercent, 2, lp);

            if (lpEnd == -1) {
                lpEnd = description.length() - 1;
            }
            int lpStart = lp + u_strlen(gLenientParse);
            while (PatternProps::isWhiteSpace(description.charAt(lpStart))) {
                ++lpStart;
            }

            // copy out the lenient-parse rules and delete them
            // from the description
            lenientParseRules = new UnicodeString();
            /* test for NULL */
            if (lenientParseRules == 0) {
                status = U_MEMORY_ALLOCATION_ERROR;
                return;
            }
            lenientParseRules->setTo(description, lpStart, lpEnd - lpStart);

            description.remove(lp, lpEnd + 1 - lp);
        }
    }

    // pre-flight parsing the description and count the number of
    // rule sets (";%" marks the end of one rule set and the beginning
    // of the next)
    numRuleSets = 0;
    for (int32_t p = description.indexOf(gSemiPercent, 2, 0); p != -1; p = description.indexOf(gSemiPercent, 2, p)) {
        ++numRuleSets;
        ++p;
    }
    ++numRuleSets;

    // our rule list is an array of the appropriate size
    ruleSets = (NFRuleSet **)uprv_malloc((numRuleSets + 1) * sizeof(NFRuleSet *));
    /* test for NULL */
    if (ruleSets == 0) {
        status = U_MEMORY_ALLOCATION_ERROR;
        return;
    }

    for (int i = 0; i <= numRuleSets; ++i) {
        ruleSets[i] = NULL;
    }

    // divide up the descriptions into individual rule-set descriptions
    // and store them in a temporary array.  At each step, we also
    // new up a rule set, but all this does is initialize its name
    // and remove it from its description.  We can't actually parse
    // the rest of the descriptions and finish initializing everything
    // because we have to know the names and locations of all the rule
    // sets before we can actually set everything up
    if(!numRuleSets) {
        status = U_ILLEGAL_ARGUMENT_ERROR;
        return;
    }

    ruleSetDescriptions = new UnicodeString[numRuleSets];
    if (ruleSetDescriptions == 0) {
        status = U_MEMORY_ALLOCATION_ERROR;
        return;
    }

    {
        int curRuleSet = 0;
        int32_t start = 0;
        for (int32_t p = description.indexOf(gSemiPercent, 2, 0); p != -1; p = description.indexOf(gSemiPercent, 2, start)) {
            ruleSetDescriptions[curRuleSet].setTo(description, start, p + 1 - start);
            ruleSets[curRuleSet] = new NFRuleSet(ruleSetDescriptions, curRuleSet, status);
            if (ruleSets[curRuleSet] == 0) {
                status = U_MEMORY_ALLOCATION_ERROR;
                return;
            }
            ++curRuleSet;
            start = p + 1;
        }
        ruleSetDescriptions[curRuleSet].setTo(description, start, description.length() - start);
        ruleSets[curRuleSet] = new NFRuleSet(ruleSetDescriptions, curRuleSet, status);
        if (ruleSets[curRuleSet] == 0) {
            status = U_MEMORY_ALLOCATION_ERROR;
            return;
        }
    }

    // now we can take note of the formatter's default rule set, which
    // is the last public rule set in the description (it's the last
    // rather than the first so that a user can create a new formatter
    // from an existing formatter and change its default behavior just
    // by appending more rule sets to the end)

    // {dlf} Initialization of a fraction rule set requires the default rule
    // set to be known.  For purposes of initialization, this is always the
    // last public rule set, no matter what the localization data says.
    initDefaultRuleSet();

    // finally, we can go back through the temporary descriptions
    // list and finish seting up the substructure (and we throw
    // away the temporary descriptions as we go)
    {
        for (int i = 0; i < numRuleSets; i++) {
            ruleSets[i]->parseRules(ruleSetDescriptions[i], this, status);
        }
    }

    // Now that the rules are initialized, the 'real' default rule
    // set can be adjusted by the localization data.

    // The C code keeps the localization array as is, rather than building
    // a separate array of the public rule set names, so we have less work
    // to do here-- but we still need to check the names.

    if (localizationInfos) {
        // confirm the names, if any aren't in the rules, that's an error
        // it is ok if the rules contain public rule sets that are not in this list
        for (int32_t i = 0; i < localizationInfos->getNumberOfRuleSets(); ++i) {
            UnicodeString name(TRUE, localizationInfos->getRuleSetName(i), -1);
            NFRuleSet* rs = findRuleSet(name, status);
            if (rs == NULL) {
                break; // error
            }
            if (i == 0) {
                defaultRuleSet = rs;
            }
        }
    } else {
        defaultRuleSet = getDefaultRuleSet();
    }
}
Ejemplo n.º 10
0
TEST(TextTest, test_stripWhitespace)
{
  std::string s("foo  \n");
  stripWhitespace(s);
  EXPECT_EQ("foo", s);
}