static void parseFunction (const unsigned char *line) { vString *name = vStringNew (); /* boolean inFunction = FALSE; */ int scope; const unsigned char *cp = line + 1; if ((int) *++cp == 'n' && (int) *++cp == 'c' && (int) *++cp == 't' && (int) *++cp == 'i' && (int) *++cp == 'o' && (int) *++cp == 'n') ++cp; if ((int) *cp == '!') ++cp; if (isspace ((int) *cp)) { while (*cp && isspace ((int) *cp)) ++cp; if (*cp) { cp = skipPrefix (cp, &scope); if (isupper ((int) *cp) || scope == 's' || /* script scope */ scope == '<' || /* script scope */ scope == 'd' || /* dictionary */ scope == 'a') /* autoload */ { do { vStringPut (name, (int) *cp); ++cp; } while (isalnum ((int) *cp) || *cp == '_' || *cp == '.' || *cp == '#'); vStringTerminate (name); makeSimpleTag (name, VimKinds, K_FUNCTION); vStringClear (name); } } } /* TODO - update struct to indicate inside function */ while ((line = readVimLine ()) != NULL) { /* * Vim7 added the for/endfo[r] construct, so we must first * check for an "endfo", before a "endf" */ if ( (!strncmp ((const char*) line, "endfo", (size_t) 5) == 0) && (strncmp ((const char*) line, "endf", (size_t) 4) == 0) ) break; /* TODO - call parseVimLine */ } vStringDelete (name); }
path remove_prefix(const path& pth, const path& prefix) { path::const_iterator it; if (!skipPrefix(pth, prefix, it)) { throw filesystem_error( "Path does not start with prefix", pth, prefix, bsys::errc::make_error_code(bsys::errc::invalid_argument)); } path p; for (; it != pth.end(); ++it) { p /= *it; } return p; }
static void parseFunction (const unsigned char *line) { vString *name = vStringNew (); /* boolean inFunction = FALSE; */ int scope; const unsigned char *cp = line; if ((int) *cp == '!') ++cp; if (isspace ((int) *cp)) { while (*cp && isspace ((int) *cp)) ++cp; if (*cp) { cp = skipPrefix (cp, &scope); if (isupper ((int) *cp) || scope == 's' || /* script scope */ scope == '<' || /* script scope */ scope == 'd' || /* dictionary */ scope == 'a') /* autoload */ { do { vStringPut (name, (int) *cp); ++cp; } while (isalnum ((int) *cp) || *cp == '_' || *cp == '.' || *cp == '#'); vStringTerminate (name); makeSimpleTag (name, VimKinds, K_FUNCTION); vStringClear (name); } } } /* TODO - update struct to indicate inside function */ while ((line = readVimLine ()) != NULL) { if (wordMatchLen (line, "endfunction", 4)) break; parseVimLine(line, TRUE); } vStringDelete (name); }
static void parseFunction (const unsigned char *line) { vString *name = vStringNew (); /* boolean inFunction = FALSE; */ int scope; const unsigned char *cp = line; int index = CORK_NIL; if (*cp == '!') ++cp; if (isspace ((int) *cp)) { while (*cp && isspace ((int) *cp)) ++cp; if (*cp) { cp = skipPrefix (cp, &scope); if (isupper ((int) *cp) || scope == 's' || /* script scope */ scope == '<' || /* script scope */ scope == 'd' || /* dictionary */ scope == 'a') /* autoload */ { char prefix[3] = { [0] = (char)scope, [1] = ':', [2] = '\0' }; if (scope == 's') vStringCatS (name, prefix); do { vStringPut (name, (int) *cp); ++cp; } while (isalnum ((int) *cp) || *cp == '_' || *cp == '.' || *cp == '#'); vStringTerminate (name); index = makeSimpleTag (name, VimKinds, K_FUNCTION); vStringClear (name); } } }
bool starts_with(const path& pth, const path& prefix) { path::const_iterator it; return skipPrefix(pth, prefix, it); }
static void findVimTags (void) { vString *name = vStringNew (); const unsigned char *line; boolean inFunction = FALSE; int scope; while ((line = fileReadLine ()) != NULL) { while (isspace ((int) *line)) ++line; if ((int) *line == '"') continue; /* skip comment */ if (strncmp ((const char*) line, "fu", (size_t) 2) == 0) { const unsigned char *cp = line + 1; inFunction = TRUE; if ((int) *++cp == 'n' && (int) *++cp == 'c' && (int) *++cp == 't' && (int) *++cp == 'i' && (int) *++cp == 'o' && (int) *++cp == 'n') ++cp; if ((int) *cp == '!') ++cp; if (isspace ((int) *cp)) { while (isspace ((int) *cp)) ++cp; cp = skipPrefix (cp, &scope); if (isupper ((int) *cp) || scope == 's' || scope == '<') { do { vStringPut (name, (int) *cp); ++cp; } while (isalnum ((int) *cp) || *cp == '_'); vStringTerminate (name); makeSimpleTag (name, VimKinds, K_FUNCTION); vStringClear (name); } } } if (strncmp ((const char*) line, "aug", (size_t) 3) == 0) { /* Found Autocommand Group (augroup) */ const unsigned char *cp = line + 2; if ((int) *++cp == 'r' && (int) *++cp == 'o' && (int) *++cp == 'u' && (int) *++cp == 'p') ++cp; if (isspace ((int) *cp)) { while (isspace ((int) *cp)) ++cp; if (strncasecmp ((const char*) cp, "end", (size_t) 3) != 0) { do { vStringPut (name, (int) *cp); ++cp; } while (isalnum ((int) *cp) || *cp == '_'); vStringTerminate (name); makeSimpleTag (name, VimKinds, K_AUGROUP); vStringClear (name); } } } if (strncmp ((const char*) line, "endf", (size_t) 4) == 0) inFunction = FALSE; if (!inFunction && strncmp ((const char*) line, "let", (size_t) 3) == 0) { /* we've found a variable declared outside of a function!! */ const unsigned char *cp = line + 3; /* get the name */ if (isspace ((int) *cp)) { /* deal with spaces, $, @ and & */ while (!isalnum ((int) *cp)) ++cp; cp = skipPrefix (cp, &scope); do { vStringPut (name, (int) *cp); ++cp; } while (isalnum ((int) *cp) || *cp == '_'); vStringTerminate (name); makeSimpleTag (name, VimKinds, K_VARIABLE); vStringClear (name); } } } vStringDelete (name); }
int IndexCursor::skipToNextKey( const BSONObj ¤tKey ) { int skipPrefixIndex = _boundsIterator->advance( currentKey ); if ( skipPrefixIndex == -2 ) { // We are done iterating completely. _ok = false; return -2; } else if ( skipPrefixIndex == -1 ) { // We should skip nothing. return -1; } // We should skip to a further key, efficiently. // // If after(), skip to the first key greater/less than the key comprised // of the first "skipPrefixIndex" elements of currentKey, and the rest // set to MaxKey/MinKey for direction > 0 and direction < 0 respectively. // eg: skipPrefixIndex = 1, currKey {a:1, b:2, c:1}, direction > 0, so we skip // to the first key greater than {a:1, b:maxkey, c:maxkey} // // If after() is false, we use the same key prefix but set the reamining // elements to the elements described by cmp(), in order. // eg: skipPrefixIndex = 1, currKey {a:1, b:2, c:1}) and cmp() [b:5, c:11] // so we use skip to {a:1, b:5, c:11}, also noting direction. if ( _boundsIterator->after() ) { skipPrefix( currentKey, skipPrefixIndex ); } else { BSONObjBuilder b(currentKey.objsize()); BSONObjIterator it = currentKey.begin(); const vector<const BSONElement *> &endKeys = _boundsIterator->cmp(); const int nFields = currentKey.nFields(); for ( int i = 0; i < nFields; i++ ) { if ( i < skipPrefixIndex ) { verify( it.more() ); b.append( it.next() ); } else { b.appendAs( *endKeys[i] , "" ); } } findKey( b.done() ); // Skip passed key prefixes that are not supposed to be inclusive // as described by _boundsIterator->inc() and endKeys // // We'll spend at worst nFields^2 time ensuring all key elements // are properly set if all the inclusive bits are false and we // keep landing on keys where the ith element of curr == endkeys[i]. // // This complexity is usually ok, since this skipping is supposed to // save us from really big linear scans across the key space in // some pathological cases. It's not clear whether or not small // cases are hurt too badly by this algorithm. bool allInclusive = true; const vector<bool> &inclusive = _boundsIterator->inc(); for ( int i = 0; i < nFields; i++ ) { if ( !inclusive[i] ) { allInclusive = false; break; } } again: while ( !allInclusive && ok() ) { BSONObj key = _currKey; it = key.begin(); dassert( nFields == key.nFields() ); for ( int i = 0; i < nFields; i++ ) { const BSONElement e = it.next(); if ( i >= skipPrefixIndex && !inclusive[i] && e.valuesEqual(*endKeys[i]) ) { // The ith element equals the ith endKey but it's not supposed to be inclusive. // Skipping to the next value for the ith element involves skipping a prefix // with i + 1 elements. skipPrefix( key, i + 1 ); goto again; } } break; } } return 0; }