size_t LogName::hash(StringPiece name) { // Code based on StringPiece::hash(), but which ignores leading and trailing // category separator characters, as well as multiple consecutive separator // characters, so equivalent names result in the same hash. uint32_t hash = 5381; size_t end = name.size(); while (end > 0 && isSeparator(name[end - 1])) { --end; } bool ignoreSeparator = true; for (size_t idx = 0; idx < end; ++idx) { uint8_t value; if (isSeparator(name[idx])) { if (ignoreSeparator) { continue; } value = '.'; ignoreSeparator = true; } else { value = static_cast<uint8_t>(name[idx]); ignoreSeparator = false; } hash = ((hash << 5) + hash) + value; } return hash; }
StringPiece LogName::getParent(StringPiece name) { if (name.empty()) { return name; } ssize_t idx = name.size(); // Skip over any trailing separator characters while (idx > 0 && isSeparator(name[idx - 1])) { --idx; } // Now walk backwards to the next separator character while (idx > 0 && !isSeparator(name[idx - 1])) { --idx; } // And again skip over any separator characters, in case there are multiple // repeated characters. while (idx > 0 && isSeparator(name[idx - 1])) { --idx; } return StringPiece(name.begin(), idx); }
Boolean RTSPOptionIsSupported(char const* commandName, char const* optionsResponseString) { do { if (commandName == NULL || optionsResponseString == NULL) break; unsigned const commandNameLen = strlen(commandName); if (commandNameLen == 0) break; // "optionsResponseString" is assumed to be a list of command names, separated by " " and/or ",", ";", or ":" // Scan through these, looking for "commandName". while (1) { // Skip over separators: while (*optionsResponseString != '\0' && isSeparator(*optionsResponseString)) ++optionsResponseString; if (*optionsResponseString == '\0') break; // At this point, "optionsResponseString" begins with a command name (with perhaps a separator afterwads). if (strncmp(commandName, optionsResponseString, commandNameLen) == 0) { // We have at least a partial match here. optionsResponseString += commandNameLen; if (*optionsResponseString == '\0' || isSeparator(*optionsResponseString)) return True; } // No match. Skip over the rest of the command name: while (*optionsResponseString != '\0' && !isSeparator(*optionsResponseString)) ++optionsResponseString; } } while (0); return False; }
// Gets the length of the prefix of [path] that defines its absolute root. // // Returns 1 the leading "/". On Windows, also handles drive letters ("C:" or // "C:\"). // // If the path is not absolute, returns 0. static size_t absolutePrefixLength(const char* path) { #ifdef _WIN32 // Drive letter. if (isDriveLetter(path[0]) && path[1] == ':') { if (isSeparator(path[2])) { // Fully absolute path. return 3; } else { // "Half-absolute" path like "C:", which is relative to the current // working directory on drive. It's absolute for our purposes. return 2; } } // TODO: UNC paths. #endif // POSIX-style absolute path or absolute path in the current drive on Windows. if (isSeparator(path[0])) return 1; // Not absolute. return 0; }
void processFeaturesString(StringView features, std::function<void(StringView type, StringView value)> callback) { unsigned length = features.length(); for (unsigned i = 0; i < length; ) { // skip to first non-separator while (i < length && isSeparator(features[i])) ++i; unsigned keyBegin = i; // skip to first separator while (i < length && !isSeparator(features[i])) i++; unsigned keyEnd = i; // skip to first '=', but don't skip past a ',' while (i < length && features[i] != '=' && features[i] != ',') ++i; // skip to first non-separator, but don't skip past a ',' while (i < length && isSeparator(features[i]) && features[i] != ',') ++i; unsigned valueBegin = i; // skip to first separator while (i < length && !isSeparator(features[i])) ++i; unsigned valueEnd = i; callback(features.substring(keyBegin, keyEnd - keyBegin), features.substring(valueBegin, valueEnd - valueBegin)); } }
std::string LogName::canonicalize(StringPiece input) { std::string cname; cname.reserve(input.size()); // Ignore trailing category separator characters size_t end = input.size(); while (end > 0 && isSeparator(input[end - 1])) { --end; } bool ignoreSeparator = true; for (size_t idx = 0; idx < end; ++idx) { if (isSeparator(input[idx])) { if (ignoreSeparator) { continue; } cname.push_back('.'); ignoreSeparator = true; } else { cname.push_back(input[idx]); ignoreSeparator = false; } } return cname; }
inline bool SearchBuffer::isWordStartMatch(size_t start, size_t length) const { ASSERT(m_options & AtWordStarts); if (!start) return true; int size = m_buffer.size(); int offset = start; UChar32 firstCharacter; U16_GET(m_buffer.data(), 0, offset, size, firstCharacter); if (m_options & TreatMedialCapitalAsWordStart) { UChar32 previousCharacter; U16_PREV(m_buffer.data(), 0, offset, previousCharacter); if (isSeparator(firstCharacter)) { // The start of a separator run is a word start (".org" in "webkit.org"). if (!isSeparator(previousCharacter)) return true; } else if (isASCIIUpper(firstCharacter)) { // The start of an uppercase run is a word start ("Kit" in "WebKit"). if (!isASCIIUpper(previousCharacter)) return true; // The last character of an uppercase run followed by a non-separator, non-digit // is a word start ("Request" in "XMLHTTPRequest"). offset = start; U16_FWD_1(m_buffer.data(), offset, size); UChar32 nextCharacter = 0; if (offset < size) U16_GET(m_buffer.data(), 0, offset, size, nextCharacter); if (!isASCIIUpper(nextCharacter) && !isASCIIDigit(nextCharacter) && !isSeparator(nextCharacter)) return true; } else if (isASCIIDigit(firstCharacter)) { // The start of a digit run is a word start ("2" in "WebKit2"). if (!isASCIIDigit(previousCharacter)) return true; } else if (isSeparator(previousCharacter) || isASCIIDigit(previousCharacter)) { // The start of a non-separator, non-uppercase, non-digit run is a word start, // except after an uppercase. ("org" in "webkit.org", but not "ore" in "WebCore"). return true; } } // Chinese and Japanese lack word boundary marks, and there is no clear agreement on what constitutes // a word, so treat the position before any CJK character as a word start. if (Character::isCJKIdeographOrSymbol(firstCharacter)) return true; size_t wordBreakSearchStart = start + length; while (wordBreakSearchStart > start) wordBreakSearchStart = findNextWordFromIndex(m_buffer.data(), m_buffer.size(), wordBreakSearchStart, false /* backwards */); if (wordBreakSearchStart != start) return false; if (m_options & WholeWord) return static_cast<int>(start + length) == findWordEndBoundary(m_buffer.data(), m_buffer.size(), wordBreakSearchStart); return true; }
vector<string> AutoCompletionAgent::tokenize(string s){ vector<string> ans; ans.clear(); int pos = 0; while (pos < s.length()){ while (pos < s.length() && isSeparator(s[pos])) pos++; int pos0 = pos; int len = 0; while (pos < s.length() && !isSeparator(s[pos])){ pos++; len++; } if (len!=0) ans.push_back(s.substr(pos0,len)); } return ans; }
PathType pathType(const char* path) { if (absolutePrefixLength(path) > 0) return PATH_TYPE_ABSOLUTE; // See if it must be relative. if ((path[0] == '.' && isSeparator(path[1])) || (path[0] == '.' && path[1] == '.' && isSeparator(path[2]))) { return PATH_TYPE_RELATIVE; } // Otherwise, we don't know. return PATH_TYPE_SIMPLE; }
// ------------------------------------------------------------------- // Get values for a new material description void ObjFileParser::getMaterialDesc() { // Get next data for material data m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); if (m_DataIt == m_DataItEnd) return; char *pStart = &(*m_DataIt); while ( !isSeparator(*m_DataIt) && m_DataIt != m_DataItEnd ) ++m_DataIt; // Get name std::string strName(pStart, &(*m_DataIt)); if ( strName.empty()) return; // Search for material std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( strName ); if ( it == m_pModel->m_MaterialMap.end() ) { // Not found, use default material m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial; } else { // Found, using detected material m_pModel->m_pCurrentMaterial = (*it).second; m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strName ); } // Skip rest of line m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine ); }
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (isSeparator(index)) { QRect rect = option.rect; #if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) if (const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3*>(&option)) { if (const QAbstractItemView *view = qobject_cast<const QAbstractItemView*>(v3->widget)) { rect.setWidth(view->viewport()->width()); } } #else if (const QAbstractItemView *view = qobject_cast<const QAbstractItemView*>(option.widget)) { rect.setWidth(view->viewport()->width()); } #endif QStyleOption opt; opt.rect = rect; this->ComboBox->style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &opt, painter, this->ComboBox); } else { QItemDelegate::paint(painter, option, index); } }
// ------------------------------------------------------------------- // Set a new material definition as the current material. void ObjFileParser::getNewMaterial() { m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd); if( m_DataIt == m_DataItEnd ) { return; } char *pStart = &(*m_DataIt); std::string strMat( pStart, *m_DataIt ); while( m_DataIt != m_DataItEnd && isSeparator( *m_DataIt ) ) { ++m_DataIt; } std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( strMat ); if ( it == m_pModel->m_MaterialMap.end() ) { // Show a warning, if material was not found DefaultLogger::get()->warn("OBJ: Unsupported material requested: " + strMat); m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial; } else { // Set new material if ( needsNewMesh( strMat ) ) { createMesh(); } m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strMat ); } m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine ); }
char *OpenDDLParser::parseBooleanLiteral( char *in, char *end, Value **boolean ) { *boolean = ddl_nullptr; if( ddl_nullptr == in || in == end ) { return in; } in = lookForNextToken( in, end ); char *start( in ); size_t len( 0 ); while( !isSeparator( *in ) && in != end ) { ++in; ++len; } ++len; int res = ::strncmp( Grammar::BoolTrue, start, strlen( Grammar::BoolTrue ) ); if( 0 != res ) { res = ::strncmp( Grammar::BoolFalse, start, strlen( Grammar::BoolFalse ) ); if( 0 != res ) { *boolean = ddl_nullptr; return in; } *boolean = ValueAllocator::allocPrimData( Value::ddl_bool ); (*boolean)->setBool( false ); } else { *boolean = ValueAllocator::allocPrimData( Value::ddl_bool ); (*boolean)->setBool( true ); } return in; }
/** * Returns index of start of current word */ int LineEditor::curWordStart( int pos ) const { // go to start of separating block while (pos > 0 && isSeparator( editString_[ pos - 1 ] )) { --pos; } // go to start of word while (pos > 0 && !isSeparator( editString_[ pos - 1 ] )) { --pos; } return pos; }
void pCheckComboBox::showPopup() { if ( !model() ) { return; } Q_ASSERT( model()->inherits( "pGenericTableModel" ) ); const Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; for ( int i = 0; i < model()->rowCount( rootModelIndex() ); i++ ) { const QModelIndex index = modelIndex( i ); if ( isSeparator( index.row() ) ) { continue; } model()->setData( index, QSize( 0, 21 ), Qt::SizeHintRole ); if ( model()->inherits( "pGenericTableModel" ) ) { model()->setData( index, QVariant::fromValue( flags ), pGenericTableModel::ItemFlagsRole ); } if ( index.data( Qt::CheckStateRole ).isNull() ) { model()->setData( index, Qt::Unchecked, Qt::CheckStateRole ); } } pComboBox::showPopup(); }
char *OpenDDLParser::parseIdentifier( char *in, char *end, Text **id ) { *id = ddl_nullptr; if( ddl_nullptr == in || in == end ) { return in; } // ignore blanks in = lookForNextToken( in, end ); // staring with a number is forbidden if( isNumeric<const char>( *in ) ) { return in; } // get size of id size_t idLen( 0 ); char *start( in ); while( !isSeparator( *in ) && !isNewLine( *in ) && ( in != end ) && *in != Grammar::OpenPropertyToken[ 0 ] && *in != Grammar::ClosePropertyToken[ 0 ] && *in != '$' ) { ++in; ++idLen; } const size_t len( idLen ); *id = new Text( start, len ); return in; }
// ------------------------------------------------------------------- // Stores values for a new object instance, name will be used to // identify it. void ObjFileParser::getObjectName() { m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); if (m_DataIt == m_DataItEnd) return; char *pStart = &(*m_DataIt); while ( m_DataIt != m_DataItEnd && !isSeparator( *m_DataIt ) ) ++m_DataIt; std::string strObjectName(pStart, &(*m_DataIt)); if (!strObjectName.empty()) { // Reset current object m_pModel->m_pCurrent = NULL; // Search for actual object for (std::vector<ObjFile::Object*>::const_iterator it = m_pModel->m_Objects.begin(); it != m_pModel->m_Objects.end(); ++it) { if ((*it)->m_strObjName == strObjectName) { m_pModel->m_pCurrent = *it; break; } } // Allocate a new object, if current one was not found before if ( NULL == m_pModel->m_pCurrent ) createObject(strObjectName); } m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine ); }
// public static String Path::combine (const String& path1, const String& path2) { if (path1.isEmpty () && path2.isEmpty ()) THROW("IDS_ILLEGAL_PATH"); if (path1.findFirstOf (Path::invalidPathChars, 0) != String::NO_POSITION) THROW("IDS_ILLEGAL_PATH"); if (path1.isEmpty ()) return path2; if (path2.isEmpty ()) return path1; if (Path::isAbsolutePath (path2)) return path2; // // isAbsolutePath have checked the invalid characters of the path2 // if (isSeparator (path1 [(int) path1.getLength () - 1])) return path1 + path2; String result (path1); result += Path::separator; result += path2; return result; }
/** * Replaces the occurences of 't' in a formula with another character */ static string replaceTimeBy(const string& src, char r) { string dst; char pre = 0; for (size_t i=0; i < src.size(); i++) { char x = src[i]; if ((x=='t') && isSeparator(pre) && ((i == src.size()-1) || isSeparator(src[i+1]))) { dst.push_back(r); } else { dst.push_back(x); } pre = x; } return dst; }
const std::string XSingleSource::getToSeparator(const char separator) { skipSpace(); std::string result; while (!isSeparator() && !isSpace() && *m_iterator != separator) result += *m_iterator++; return result; }
char *OpenDDLParser::parseIntegerLiteral( char *in, char *end, Value **integer, Value::ValueType integerType ) { *integer = ddl_nullptr; if( ddl_nullptr == in || in == end ) { return in; } if( !(isIntegerType( integerType ) || isUnsignedIntegerType(integerType)) ) { return in; } in = lookForNextToken( in, end ); char *start( in ); while( !isSeparator( *in ) && in != end ) { ++in; } if( isNumeric( *start ) ) { #ifdef OPENDDL_NO_USE_CPP11 const int64 value( atol( start ) ); // maybe not really 64bit as atoll is but exists without c++11 const uint64 uvalue( strtoul( start,ddl_nullptr,10 ) ); #else const int64 value( atoll( start ) ); const uint64 uvalue( strtoull( start,ddl_nullptr,10 ) ); #endif *integer = ValueAllocator::allocPrimData( integerType ); switch( integerType ) { case Value::ddl_int8: ( *integer )->setInt8( (int8) value ); break; case Value::ddl_int16: ( *integer )->setInt16( ( int16 ) value ); break; case Value::ddl_int32: ( *integer )->setInt32( ( int32 ) value ); break; case Value::ddl_int64: ( *integer )->setInt64( ( int64 ) value ); break; case Value::ddl_unsigned_int8: ( *integer )->setUnsignedInt8( (uint8) uvalue ); break; case Value::ddl_unsigned_int16: ( *integer )->setUnsignedInt16( ( uint16 ) uvalue ); break; case Value::ddl_unsigned_int32: ( *integer )->setUnsignedInt32( ( uint32 ) uvalue ); break; case Value::ddl_unsigned_int64: ( *integer )->setUnsignedInt64( ( uint64 ) uvalue ); break; default: break; } } return in; }
QSize pCheckComboBoxDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const { if ( isSeparator( index ) ) { int pm = mCombo->style()->pixelMetric( QStyle::PM_DefaultFrameWidth, 0, mCombo ); return QSize( pm, pm ); } return QStyledItemDelegate::sizeHint( option, index ); }
int nextSeparator(char *line, char type) { int i = 0, size = (int) strlen(line); switch (type) { case 's': i++; while ( i < size && line[i] != '\n' && line[i] != '\t' && line[i] != 0 && line[i] != '\"' && line[i] != EOF) if (line[i] == '\\' && (line[i+1] == '\'' || line[i+1] == '\"' || line[i+1] == 't' || line[i+1] == 'n' || line[i+1] == '\\')) i+=2; else i++; i++; break; case 'c': i++; while ( i < size && line[i] != '\n' && line[i] != '\t' && line[i] != 0 && line[i] != '\'' && line[i] != EOF) if (line[i] == '\\' && (line[i+1] == '\'' || line[i+1] == '\"' || line[i+1] == 't' || line[i+1] == 'n' || line[i+1] == '\\')) i+=2; else i++; i++; break; case 'n': case 'i': while ( i < size && line[i] != EOF && !isSeparator(line[i]) && isalnum(line[i])) i++; break; case 't': if ((line[i] == '<' && (line[i+1] == '>' || line[i+1] == '=')) || (line[i] == '>' && line[i+1] == '=')) i = 2; else i = 1; } return i; }
void pathJoin(Path* path, const char* string) { if (path->length > 0 && !isSeparator(path->chars[path->length - 1])) { pathAppendChar(path, '/'); } pathAppendString(path, string); }
inline uchar getNextWord(const char* text, char* buff){ uchar nchar = 0; while(!isSeparator(text[nchar])){ buff[nchar] = text[nchar]; ++nchar; } buff[nchar] = '\0'; return nchar + 1; }
/** * Returns index of end of current word */ int LineEditor::curWordEnd( int pos ) const { // go to end of word while (uint( pos ) < editString_.length() && !isSeparator( editString_[ pos ] )) { ++pos; } // go to end of separating block while (uint( pos ) < editString_.length() && isSeparator( editString_[ pos ] )) { ++pos; } return pos; }
int LogName::cmp(StringPiece a, StringPiece b) { // Ignore trailing separators auto stripTrailingSeparators = [](StringPiece& s) { while (!s.empty() && isSeparator(s.back())) { s.uncheckedSubtract(1); } }; stripTrailingSeparators(a); stripTrailingSeparators(b); // Advance ptr until it no longer points to a category separator. // This is used to skip over consecutive sequences of separator characters. auto skipOverSeparators = [](StringPiece& s) { while (!s.empty() && isSeparator(s.front())) { s.uncheckedAdvance(1); } }; bool ignoreSeparator = true; while (true) { if (ignoreSeparator) { skipOverSeparators(a); skipOverSeparators(b); } if (a.empty()) { return b.empty() ? 0 : -1; } else if (b.empty()) { return 1; } if (isSeparator(a.front())) { if (!isSeparator(b.front())) { return '.' - b.front(); } ignoreSeparator = true; } else { if (a.front() != b.front()) { return a.front() - b.front(); } ignoreSeparator = false; } a.uncheckedAdvance(1); b.uncheckedAdvance(1); } }
void MeshManager::getNextWord(char* buffer, int* i){ //logInf("i value %i",*i); while(isSeparator(buffer[*i]) && buffer[*i] != '\0'){//changed! (*i)++; // logInf("getNextWord value %c at position %i", buffer[*i], (*i)); } /* while(buffer[*i] == ' '){ (*i)++; }*/ }
void Path::split(const String &path,String& dirpath, String& filename) { if (path.isEmpty ()) THROW("IDS_ILLEGAL_PATH"); if (path.findFirstOf (Path::invalidPathChars, 0) != String::NO_POSITION) THROW("IDS_ILLEGAL_PATH"); dirpath.clear(); filename.clear(); String p = Path::adaptSep(path); #ifdef __WINDOWS__ // TODO // deal route like \\.\device\somthing // and \\?\volume\something // and driver: like C: // C:dir should throw an error? #endif // deal when start with separator size_t headSlashNum = 0; if (isSeparator(p[0])) { while (isSeparator( p[headSlashNum])) { dirpath += Path::separator; headSlashNum++; if (headSlashNum == p.getLength()) { break; } } } p = p.subString(headSlashNum); // find most right sep pos size_t posLastSlash = p.findLastOf(Path::separator); if (posLastSlash == p.getLength() - 1) { dirpath += p.subString(0, p.getLength() - 1); filename = String::EMPTY; } else if (posLastSlash == String::NO_POSITION) { filename = p; } else { dirpath += String(p, 0, posLastSlash); filename.assign(p, posLastSlash + 1, String::NO_POSITION); } }
string combine(string basePath,string fileName) { if (basePath.length() > 0) { if (!isSeparator(basePath.lastChar())) { basePath += getDefaultSeparator(); } return basePath + fileName; } else { //todo? return fileName; } }