static asstring_t *objectString_Trim( asstring_t *self ) { asstring_t *string = objectString_FactoryBuffer( self->buffer, self->len ); if( string->len ) Q_trim( string->buffer ); return string; }
/* * G_SanitizeUserString */ static int G_SanitizeUserString( char *string, size_t size ) { static char *colorless = NULL; static size_t colorless_size = 0; int i, c_ascii; // life is hard, UTF-8 will have to go strip_highchars( string ); COM_SanitizeColorString( va( "%s", string ), string, size, -1, COLOR_WHITE ); Q_trim( string ); if( colorless_size < strlen( string ) + 1 ) { colorless_size = strlen( string ) + 1; G_Free( colorless ); colorless = ( char * )G_Malloc( colorless_size ); } Q_strncpyz( colorless, COM_RemoveColorTokens( string ), colorless_size ); // require at least one non-whitespace ascii char in the string // (this will upset people who would like to have a name entirely in a non-latin // script, but it makes damn sure you can't get an empty name by exploiting some // utf-8 decoder quirk) c_ascii = 0; for( i = 0; colorless[i]; i++ ) if( colorless[i] > 32 && colorless[i] < 127 ) c_ascii++; return c_ascii; }
/* * S_ReadPlaylistFile */ static bgTrack_t *S_ReadPlaylistFile( const char *filename, bool shuffle, bool loop ) { int filenum, length; char *tmpname = 0; size_t tmpname_size = 0; char *data, *line, *entry; playlistItem_t items[MAX_PLAYLIST_ITEMS]; int i, numItems = 0; length = trap_FS_FOpenFile( filename, &filenum, FS_READ ); if( length < 0 ) return NULL; // load the playlist into memory data = S_Malloc( length + 1 ); trap_FS_Read( data, length, filenum ); trap_FS_FCloseFile( filenum ); srand( time( NULL ) ); while( *data ) { size_t s; entry = data; // read the whole line for( line = data; *line != '\0' && *line != '\n'; line++ ); // continue reading from the next character, if possible data = (*line == '\0' ? line : line + 1); *line = '\0'; // trim whitespaces, tabs, etc entry = Q_trim( entry ); // special M3U entry or comment if( !*entry || *entry == '#' ) continue; if( trap_FS_IsUrl( entry ) ) { items[numItems].track = S_AllocTrack( entry ); } else { // append the entry name to playlist path s = strlen( filename ) + 1 + strlen( entry ) + 1; if( s > tmpname_size ) { if( tmpname ) S_Free( tmpname ); tmpname_size = s; tmpname = S_Malloc( tmpname_size ); } Q_strncpyz( tmpname, filename, tmpname_size ); COM_StripFilename( tmpname ); Q_strncatz( tmpname, "/", tmpname_size ); Q_strncatz( tmpname, entry, tmpname_size ); COM_SanitizeFilePath( tmpname ); items[numItems].track = S_AllocTrack( tmpname ); } if( ++numItems == MAX_PLAYLIST_ITEMS ) break; } if( tmpname ) { S_Free( tmpname ); tmpname = NULL; } if( !numItems ) return NULL; // set the playing order for( i = 0; i < numItems; i++ ) items[i].order = (shuffle ? (rand() % numItems) : i); // sort the playlist R_SortPlaylistItems( numItems, items ); // link the playlist for( i = 1; i < numItems; i++ ) { items[i-1].track->next = items[i].track; items[i].track->prev = items[i-1].track; items[i].track->loop = loop; } items[numItems-1].track->next = items[0].track; items[0].track->prev = items[numItems-1].track; items[0].track->loop = loop; return items[0].track; }
void GameAjaxDataSource::StreamDone( int status, const char *contentType, void *privatep ) { SourceFetcherPair *fp = static_cast< SourceFetcherPair *>( privatep ); DynTableFetcher *fetcher = fp->second; GameAjaxDataSource *ds = fp->first; DynTable *table = fetcher->table; std::string tableName = table->GetName(); String rocketTableName = tableName.c_str(); DynTableList::iterator t_it = ds->tableList.find( tableName ); bool hasOldTable = t_it != ds->tableList.end(); DynTableFetcher *oldFetcher = hasOldTable ? t_it->second : NULL; DynTable *oldTable = hasOldTable ? oldFetcher->table : NULL; const char *data = fetcher->buf.c_str(); // simply exit on error or if nothing has changed in table data if( status < 0 || status >= 300 || ( hasOldTable && ( oldFetcher->buf == data ) ) ) { __delete__( table ); __delete__( fetcher ); __delete__( fp ); return; } // parse server response: // { // "key1" = "value1" // "key2" = "value2" // } char *token; std::string key, value; for(; ( token = COM_Parse( &data ) ) && token[0] == '{'; ) { Row row; while( 1 ) { token = COM_ParseExt( &data, true ); if( !token[0] ) break; // error if( token[0] == '}' ) break; // end of callvote key = Q_trim( token ); value = COM_ParseExt( &data, true ); row[key] = value; } table->AddRow( row ); } if( oldTable != NULL ) { ds->tableList[tableName] = fetcher; ds->NotifyRowChange( rocketTableName ); __delete__( oldTable ); __delete__( oldFetcher ); } else { ds->tableList[tableName] = fetcher; ds->NotifyRowAdd( rocketTableName, 0, table->GetNumRows() ); } __delete__( fp ); }