From: Mattia Basaglia Date: Tue, 21 Jul 2015 05:48:37 +0000 (+0200) Subject: Convert Array to std::string X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=90a57977499daeee57c054a65f0cb68d4ab989d8;p=xonotic%2Fnetradiant.git Convert Array to std::string --- diff --git a/include/idatastream.h b/include/idatastream.h index 674c9fa9..c15991c6 100644 --- a/include/idatastream.h +++ b/include/idatastream.h @@ -23,6 +23,7 @@ #define INCLUDED_IDATASTREAM_H #include +#include class StreamBase { @@ -55,12 +56,10 @@ public: typedef int offset_type; typedef std::size_t position_type; -enum seekdir -{ - beg, - cur, - end, -}; +using seekdir = std::ios_base::seekdir; +static const auto cur = std::ios_base::cur; +static const auto beg = std::ios_base::beg; +static const auto end = std::ios_base::end; /// \brief Sets the current \p position of the stream relative to the start. virtual position_type seek( position_type position ) = 0; diff --git a/libs/container/array.h b/libs/container/array.h index 57d2f6b0..e2889b37 100644 --- a/libs/container/array.h +++ b/libs/container/array.h @@ -27,7 +27,6 @@ #include "memory/allocator.h" template > using Array = std::vector; -/// \todo replace Array with std::string #if 0 #include diff --git a/libs/gtkutil/filechooser.cpp b/libs/gtkutil/filechooser.cpp index a47019f1..55130efd 100644 --- a/libs/gtkutil/filechooser.cpp +++ b/libs/gtkutil/filechooser.cpp @@ -170,22 +170,12 @@ const char* file_dialog_show( GtkWidget* parent, bool open, const char* title, c if ( path != 0 && !string_empty( path ) ) { ASSERT_MESSAGE( path_is_absolute( path ), "file_dialog_show: path not absolute: " << makeQuoted( path ) ); - Array new_path( strlen( path ) + 1 ); + std::string new_path(path); + std::replace(new_path.begin(), new_path.end(), '/', G_DIR_SEPARATOR); + if ( !new_path.empty() && new_path.back() == G_DIR_SEPARATOR ) + new_path.pop_back(); - // copy path, replacing dir separators as appropriate - Array::iterator w = new_path.begin(); - for ( const char* r = path; *r != '\0'; ++r ) - { - *w++ = ( *r == '/' ) ? G_DIR_SEPARATOR : *r; - } - // remove separator from end of path if required - if ( *( w - 1 ) == G_DIR_SEPARATOR ) { - --w; - } - // terminate string - *w = '\0'; - - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), new_path.data() ); + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), new_path.c_str() ); } // we should add all important paths as shortcut folder... diff --git a/plugins/archivezip/archive.cpp b/plugins/archivezip/archive.cpp index 1136a5c0..2c29a139 100644 --- a/plugins/archivezip/archive.cpp +++ b/plugins/archivezip/archive.cpp @@ -148,20 +148,20 @@ bool read_record(){ istream_read_int32_le( m_istream ); unsigned int position = istream_read_int32_le( m_istream ); - Array filename( namelength + 1 ); - m_istream.read( reinterpret_cast( filename.data() ), namelength ); - filename[namelength] = '\0'; + std::string filename( namelength, ' ' ); + if ( namelength > 0 ) + m_istream.read( reinterpret_cast( &filename[0] ), namelength ); m_istream.seek( extras + comment, FileInputStream::cur ); - if ( path_is_directory( filename.data() ) ) { - m_filesystem[filename.data()] = 0; + if ( path_is_directory( filename.c_str() ) ) { + m_filesystem[filename.c_str()] = 0; } else { - ZipFileSystem::entry_type& file = m_filesystem[filename.data()]; + ZipFileSystem::entry_type& file = m_filesystem[filename.c_str()]; if ( !file.is_directory() ) { - globalOutputStream() << "Warning: zip archive " << makeQuoted( m_name.c_str() ) << " contains duplicated file: " << makeQuoted( filename.data() ) << "\n"; + globalOutputStream() << "Warning: zip archive " << makeQuoted( m_name.c_str() ) << " contains duplicated file: " << makeQuoted( filename.c_str() ) << "\n"; } else { diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index 1e2251d3..b5a1ac59 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -215,15 +215,12 @@ bool Preferences_Save( PreferenceDictionary& preferences, const char* filename ) } bool Preferences_Save_Safe( PreferenceDictionary& preferences, const char* filename ){ - Array tmpName( filename, filename + strlen( filename ) + 1 + 3 ); - *( tmpName.end() - 4 ) = 'T'; - *( tmpName.end() - 3 ) = 'M'; - *( tmpName.end() - 2 ) = 'P'; - *( tmpName.end() - 1 ) = '\0'; + std::string tmpName( filename ); + tmpName += "TMP"; - return Preferences_Save( preferences, tmpName.data() ) + return Preferences_Save( preferences, tmpName.c_str() ) && ( !file_exists( filename ) || file_remove( filename ) ) - && file_move( tmpName.data(), filename ); + && file_move( tmpName.c_str(), filename ); } diff --git a/radiant/renderstate.cpp b/radiant/renderstate.cpp index ede25740..a899e7ed 100644 --- a/radiant/renderstate.cpp +++ b/radiant/renderstate.cpp @@ -129,8 +129,10 @@ void printShaderLog( GLhandleARB object ){ GLint log_length = 0; glGetObjectParameterivARB( object, GL_OBJECT_INFO_LOG_LENGTH_ARB, &log_length ); - Array log( log_length ); - glGetInfoLogARB( object, log_length, &log_length, log.data() ); + + std::string log( log_length, ' ' ); + if ( !log.empty() ) + glGetInfoLogARB( object, log_length, &log_length, &log[0] ); globalErrorStream() << StringRange( log.data(), log.data() + log_length ) << "\n"; }