EString ImapParser::quoted() { EString r; char c = nextChar(); if ( c != '"' ) { setError( "Expected quoted string, but saw: " + following() ); return r; } step(); c = nextChar(); while ( c != '"' && c > 0 && c != 10 && c != 13 ) { if ( c == '\\' ) { step(); c = nextChar(); if ( c == 0 || c == 10 || c == 13 ) setError( "Quoted string contained bad char: " + following() ); } step(); r.append( c ); c = nextChar(); } if ( c != '"' ) setError( "Quoted string incorrectly terminated: " + following() ); else step(); Utf8Codec utf8; UString u( utf8.toUnicode( r ) ); return utf8.fromUnicode( u ); }
EString ImapParser::quoted() { EString r; char c = nextChar(); if ( c != '"' ) { setError( "Expected quoted string, but saw: " + following() ); return r; } step(); c = nextChar(); while ( c != '"' && c < 128 && c > 0 && c != 10 && c != 13 ) { if ( c == '\\' ) { step(); c = nextChar(); if ( c == 0 || c >= 128 || c == 10 || c == 13 ) setError( "Quoted string contained bad char: " + following() ); } step(); r.append( c ); c = nextChar(); } if ( c != '"' ) setError( "Quoted string incorrectly terminated: " + following() ); else step(); return r; }
EString ImapParser::literal() { char c = nextChar(); if ( c == '~' ) { step(); c = nextChar(); } if ( c != '{' ) { setError( "Expected literal, but saw: " + following() ); return ""; } step(); uint len = number(); if ( !ok() ) return ""; if ( nextChar() == '+' ) step(); if ( nextChar() != '}' ) { setError( "Expected literal-}, but saw: " + following() ); return ""; } step(); require( "\r\n" ); if ( !ok() ) return ""; EString r( str.mid( pos(), len ) ); step( len ); return r; }
IntegerSet Command::set( bool parseMsns = false ) { IntegerSet result; ImapSession *s = 0; if ( imap() ) s = imap()->session(); uint n1 = 0, n2 = 0; bool done = false; while ( ok() && !done ) { char c = nextChar(); if ( c == '*' ) { step(); n1 = 0; if ( s ) n1 = s->largestUid(); else error( Bad, "Need a mailbox session to use * as an UID/MSN" ); } else if ( c >= '1' && c <= '9' ) { if ( parseMsns ) n1 = msn(); else n1 = nzNumber(); } else { error( Bad, "number or '*' expected, saw: " + following() ); } c = nextChar(); if ( c == ':' ) { if ( n2 ) error( Bad, "saw colon after range (" + fn( n1 ) + ":" + fn( n2 ) + "), saw:" + following() ); n2 = n1; n1 = 0; step(); } else if ( ok() ) { if ( n2 ) result.add( n1, n2 ); else result.add( n1 ); n1 = 0; n2 = 0; if ( c == ',' ) step(); else done = true; } }; return result; }
/* * Calculates the cell following a given one. Advances from top to bottom and * left to right. Returns 0 if there is no next cell, 1 otherwise and modifies * the arguments to point to the next cell in that case. */ int next_cell(int *r, int *c) { assert_(r != NULL && c != NULL); if ((*r) == MAX_NUM && (*c) == MAX_NUM) return 0; *c = following(*c); if ((*c) == MIN_NUM) (*r) = following(*r); return 1; }
/** * Returns true if the specfied position is a boundary position. As a side * effect, leaves the iterator pointing to the first boundary position at * or after "offset". * @param offset the offset to check. * @return True if "offset" is a boundary position. */ UBool BreakIterator::isBoundary(int32_t offset) { // the beginning index of the iterator is always a boundary position by definition if (offset == 0) { first(); // For side effects on current position, tag values. return TRUE; } if (offset == (int32_t)utext_nativeLength(fText)) { last(); // For side effects on current position, tag values. return TRUE; } // out-of-range indexes are never boundary positions if (offset < 0) { first(); // For side effects on current position, tag values. return FALSE; } if (offset > utext_nativeLength(fText)) { last(); // For side effects on current position, tag values. return FALSE; } // otherwise, we can use following() on the position before the specified // one and return true if the position we get back is the one the user // specified utext_previous32From(fText, offset); int32_t backOne = (int32_t)UTEXT_GETNATIVEINDEX(fText); UBool result = following(backOne) == offset; return result; }
UString SmtpParser::atom() { char c = nextChar(); EString r; while ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || ( c >= '0' && c <= '9' ) || c == '!' || c == '#' || c == '$' || c == '%' || c == '&' || c == '\'' || c == '*' || c == '+' || c == '-' || c == '/' || c == '=' || c == '?' || c == '^' || c == '_' || c == '`' || c == '{' || c == '|' || c == '}' || c == '~' || c >= 128 ) { r.append( c ); step(); c = nextChar(); } if ( r.isEmpty() ) setError( "Expected atom, saw: " + following() ); Utf8Codec uc; UString u = uc.toUnicode( r ); if ( !uc.valid() ) setError( "Unicode error in atom (" + uc.error() + "): " + r ); return u; }
class SieveCommand * SieveParser::command() { whitespace(); SieveCommand * sc = new SieveCommand; sc->setParser( this ); sc->setStart( pos() ); sc->setIdentifier( identifier() ); sc->setArguments( arguments() ); whitespace(); if ( nextChar() == '{' ) { sc->setBlock( block() ); } else if ( present( ";" ) ) { // fine } else { setError( "Garbage after command: " + following() ); // if the line ends with ';', skip ahead to it uint x = pos(); while ( x < input().length() && input()[x] != '\n' && input()[x] != '\r' ) x++; if ( x > pos() && input()[x-1] == ';' ) step( x - pos() ); } sc->setError( error() ); sc->setEnd( pos() ); return sc; }
EString SmtpParser::atom() { char c = nextChar(); EString r; while ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || ( c >= '0' && c <= '9' ) || c == '!' || c == '#' || c == '$' || c == '%' || c == '&' || c == '\'' || c == '*' || c == '+' || c == '-' || c == '/' || c == '=' || c == '?' || c == '^' || c == '_' || c == '`' || c == '{' || c == '|' || c == '}' || c == '~' ) { r.append( c ); step(); c = nextChar(); } if ( r.isEmpty() ) setError( "Expected atom, saw: " + following() ); return r; }
uint ImapParser::nzNumber() { uint n = number(); if ( ok() && n == 0 ) setError( "Expected nonzero number, but saw 0 followed by: " + following() ); return n; }
EString ImapParser::string() { char c = nextChar(); if ( c == '"' ) return quoted(); else if ( c == '{' || c == '~' ) return literal(); setError( "Expected string, but saw: " + following() ); return ""; }
void Command::space() { d->args->require( " " ); if ( d->args->nextChar() != ' ' ) return; while ( d->args->nextChar() == ' ' ) d->args->step(); (void)new ImapResponse( imap(), "BAD Illegal space seen before this text: " + following() ); }
EString SmtpParser::esmtpValue() { EString r; char c = nextChar(); while ( !atEnd() && c != '=' && c > 32 && c < 128 ) { r.append( c ); step(); c = nextChar(); } if ( r.isEmpty() ) setError( "Expected esmtp parameter value, saw: " + following() ); return r; }
EString SmtpParser::esmtpKeyword() { char c = nextChar(); EString r; while ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || ( c >= '0' && c <= '9' ) || ( c == '-' && !r.isEmpty() ) ) { r.append( c ); step(); c = nextChar(); } if ( r.isEmpty() ) setError( "Expected esmtp parameter keyword, saw: " + following() ); return r.lower(); }
EString ImapParser::tag() { EString r; char c = nextChar(); while ( c > ' ' && c < 127 && c != '(' && c != ')' && c != '{' && c != '%' && c != '*' && c != '"' && c != '\\' && c != '+' ) { step(); r.append( c ); c = nextChar(); } if ( r.isEmpty() ) setError( "Expected IMAP tag, but saw: " + following().quoted() ); return r; }
EString ImapParser::listChars() { EString r; char c = nextChar(); while ( c > ' ' && c < 127 && c != '(' && c != ')' && c != '{' && c != '"' && c != '\\' ) { step(); r.append( c ); c = nextChar(); } if ( r.isEmpty() ) setError( "Expected 1*list-char, but saw: " + following() ); return r; }
EString ImapParser::dotLetters( uint min, uint max ) { EString r; uint i = 0; char c = nextChar(); while ( i < max && ( ( c >= 'A' && c <= 'Z' ) || ( c >= 'a' && c <= 'z' ) || ( c >= '0' && c <= '9' ) || ( c == '.' ) ) ) { step(); r.append( c ); c = nextChar(); i++; } if ( i < min ) setError( "Expected at least " + fn( min-i ) + " more " "letters/digits/dots, but saw: " + following() ); return r; }
EString ImapParser::listMailbox() { EString r; char c = nextChar(); if ( c == '"' || c == '{' ) return string(); while ( c > ' ' && c != '(' && c != ')' && c != '{' && c != '"' && c != '\\' ) { step(); r.append( c ); c = nextChar(); } if ( r.isEmpty() ) setError( "Expected list-mailbox, but saw: " + following() ); return r; }
EString ImapParser::astring() { char c = nextChar(); if ( c == '"' || c == '{' ) return string(); EString r; while ( c > ' ' && c < 128 && c != '(' && c != ')' && c != '{' && c != '"' && c != '\\' && c != '%' && c != '*' ) { step(); r.append( c ); c = nextChar(); } if ( r.isEmpty() ) setError( "Expected astring, but saw: " + following() ); return r; }
EString ImapParser::command() { EString r; if ( present( "uid " ) ) r.append( "uid " ); char c = nextChar(); while ( c > ' ' && c < 127 && c != '(' && c != ')' && c != '{' && c != '%' && c != '*' && c != '"' && c != '\\' && c != ']' ) { step(); r.append( c ); c = nextChar(); } if ( r.isEmpty() || r == "uid " ) setError( "Expected IMAP command name, but saw: '" + following() + "'" ); return r; }
SUMOReal MSCFModel_Wiedemann::_v(const MSVehicle* veh, SUMOReal predSpeed, SUMOReal gap) const { const VehicleVariables* vars = (VehicleVariables*)veh->getCarFollowVariables(); const SUMOReal dx = gap + myType->getLength(); // wiedemann uses brutto gap const SUMOReal v = veh->getSpeed(); const SUMOReal vpref = veh->getMaxSpeed(); const SUMOReal dv = v - predSpeed; const SUMOReal bx = myAX + (1 + 7 * mySecurity) * sqrt(v); // Harding propose a factor of *.8 here const SUMOReal ex = 2 - myEstimation; // + RandHelper::randNorm(0.5, 0.15) const SUMOReal sdx = myAX + ex * (bx - myAX); /// the distance at which we drift out of following const SUMOReal sdv_root = (dx - myAX) / myCX; const SUMOReal sdv = sdv_root * sdv_root; const SUMOReal cldv = sdv * ex * ex; const SUMOReal opdv = cldv * (-1 - 2 * RandHelper::randNorm(0.5, 0.15)); // select the regime, get new acceleration, compute new speed based SUMOReal accel; if (dx <= bx) { accel = emergency(dv, dx); } else if (dx < sdx) { if (dv > cldv) { accel = approaching(dv, dx, bx); } else if (dv > opdv) { accel = following(vars->accelSign); } else { accel = fullspeed(v, vpref, dx, bx); } } else { if (dv > sdv && dx < D_MAX) { //@note other versions have an disjunction instead of conjunction accel = approaching(dv, dx, bx); } else { accel = fullspeed(v, vpref, dx, bx); } } // since we have hard constrainst on accel we may as well use them here accel = MAX2(MIN2(accel, myAccel), -myDecel); const SUMOReal vNew = MAX2(SUMOReal(0), v + ACCEL2SPEED(accel)); // don't allow negative speeds return vNew; }
//------------------------------------------------------------------------------- // // checkDictionary This function handles all processing of characters in // the "dictionary" set. It will determine the appropriate // course of action, and possibly set up a cache in the // process. // //------------------------------------------------------------------------------- int32_t BreakIterator::checkDictionary(int32_t startPos, int32_t endPos, UBool reverse) { #if 1 return reverse ? startPos : endPos; #else // Reset the old break cache first. uint32_t dictionaryCount = fDictionaryCharCount; reset(); if (dictionaryCount <= 1 || (endPos - startPos) <= 1) { return (reverse ? startPos : endPos); } // Starting from the starting point, scan towards the proposed result, // looking for the first dictionary character (which may be the one // we're on, if we're starting in the middle of a range). utext_setNativeIndex(fText, reverse ? endPos : startPos); if (reverse) { UTEXT_PREVIOUS32(fText); } int32_t rangeStart = startPos; int32_t rangeEnd = endPos; uint16_t category; int32_t current; UErrorCode status = U_ZERO_ERROR; UStack breaks(status); int32_t foundBreakCount = 0; UChar32 c = utext_current32(fText); UTRIE_GET16(&fData->fTrie, c, category); // Is the character we're starting on a dictionary character? If so, we // need to back up to include the entire run; otherwise the results of // the break algorithm will differ depending on where we start. Since // the result is cached and there is typically a non-dictionary break // within a small number of words, there should be little performance impact. if (category & 0x4000) { if (reverse) { do { utext_next32(fText); // TODO: recast to work directly with postincrement. c = utext_current32(fText); UTRIE_GET16(&fData->fTrie, c, category); } while (c != U_SENTINEL && (category & 0x4000)); // Back up to the last dictionary character rangeEnd = (int32_t)UTEXT_GETNATIVEINDEX(fText); if (c == U_SENTINEL) { // c = fText->last32(); // TODO: why was this if needed? c = UTEXT_PREVIOUS32(fText); } else { c = UTEXT_PREVIOUS32(fText); } } else { do { c = UTEXT_PREVIOUS32(fText); UTRIE_GET16(&fData->fTrie, c, category); } while (c != U_SENTINEL && (category & 0x4000)); // Back up to the last dictionary character if (c == U_SENTINEL) { // c = fText->first32(); c = utext_current32(fText); } else { utext_next32(fText); c = utext_current32(fText); } rangeStart = (int32_t)UTEXT_GETNATIVEINDEX(fText);; } UTRIE_GET16(&fData->fTrie, c, category); } // Loop through the text, looking for ranges of dictionary characters. // For each span, find the appropriate break engine, and ask it to find // any breaks within the span. // Note: we always do this in the forward direction, so that the break // cache is built in the right order. if (reverse) { utext_setNativeIndex(fText, rangeStart); c = utext_current32(fText); UTRIE_GET16(&fData->fTrie, c, category); } while(U_SUCCESS(status)) { while((current = (int32_t)UTEXT_GETNATIVEINDEX(fText)) < rangeEnd && (category & 0x4000) == 0) { utext_next32(fText); // TODO: tweak for post-increment operation c = utext_current32(fText); UTRIE_GET16(&fData->fTrie, c, category); } if (current >= rangeEnd) { break; } // We now have a dictionary character. Get the appropriate language object // to deal with it. const LanguageBreakEngine *lbe = getLanguageBreakEngine(c); // Ask the language object if there are any breaks. It will leave the text // pointer on the other side of its range, ready to search for the next one. if (lbe != NULL) { foundBreakCount += lbe->findBreaks(fText, rangeStart, rangeEnd, FALSE, fBreakType, breaks); } // Reload the loop variables for the next go-round c = utext_current32(fText); UTRIE_GET16(&fData->fTrie, c, category); } // If we found breaks, build a new break cache. The first and last entries must // be the original starting and ending position. if (foundBreakCount > 0) { int32_t totalBreaks = foundBreakCount; if (startPos < breaks.elementAti(0)) { totalBreaks += 1; } if (endPos > breaks.peeki()) { totalBreaks += 1; } fCachedBreakPositions = (int32_t *)uprv_malloc(totalBreaks * sizeof(int32_t)); if (fCachedBreakPositions != NULL) { int32_t out = 0; fNumCachedBreakPositions = totalBreaks; if (startPos < breaks.elementAti(0)) { fCachedBreakPositions[out++] = startPos; } for (int32_t i = 0; i < foundBreakCount; ++i) { fCachedBreakPositions[out++] = breaks.elementAti(i); } if (endPos > fCachedBreakPositions[out-1]) { fCachedBreakPositions[out] = endPos; } // If there are breaks, then by definition, we are replacing the original // proposed break by one of the breaks we found. Use following() and // preceding() to do the work. They should never recurse in this case. if (reverse) { return preceding(endPos - 1); } else { return following(startPos); } } // If the allocation failed, just fall through to the "no breaks found" case. } // If we get here, there were no language-based breaks. Set the text pointer // to the original proposed break. utext_setNativeIndex(fText, reverse ? startPos : endPos); return (reverse ? startPos : endPos); #endif }