//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void elMundo::setRules (QString ruleString) { QString::const_iterator it; int B_bitmask = 0, S_bitmask = 0; QString digits; if (reBrule.indexIn(ruleString) >= 0) { digits = reBrule.cap(1); for (it = digits.constBegin(); it != digits.constEnd(); it++) B_bitmask |= (1 << it->digitValue()); } if (reSrule.indexIn(ruleString) >= 0) { digits = reSrule.cap(1); for (it = digits.constBegin(); it != digits.constEnd(); it++) S_bitmask |= (1 << it->digitValue()); } fprintf(stderr,"Rules(%s=+%x:%x)\n", ruleString.cStr(), B_bitmask,S_bitmask); setRules(B_bitmask, S_bitmask); }
static ParseResult ParseDecimalPart(ParseResult const& begin, QString::const_iterator end) { Amount multiplier ("0.1"); //exactly 1 tenth Amount decrement ("0.1"); //exactly 1 tenth Amount a = ResultAmount(begin); QString::const_iterator iter; for (iter = ResultIter(begin); iter != end; iter++) { if (iter->isDigit()) { a += Amount(iter->digitValue())*multiplier; multiplier *= decrement; } else { throw std::runtime_error("Invalid currency string"); } } return ParseResult(a,iter); }
static ParseResult ParseWholePart(QString::const_iterator begin, QString::const_iterator end) { Amount a (0); QString::const_iterator iter; for (iter = begin; iter != end; iter++) { if (iter->isDigit()) { a *= Amount(10); //scale up a = a + Amount(iter->digitValue()); //add } else if (*iter == QLocale().groupSeparator()) { //eat it } else if (*iter == QLocale().decimalPoint()) { iter++; //skip the decimal point return ParseResult(a, iter); } else { throw std::runtime_error("Invalid currency string"); } } return ParseResult(a,iter); }