]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
gtkutil/filechooser: replace Array<char> by std::string
authorAntoine Fontaine <antoine.fontaine@epfl.ch>
Tue, 23 Mar 2021 02:38:44 +0000 (03:38 +0100)
committerAntoine Fontaine <antoine.fontaine@epfl.ch>
Tue, 23 Mar 2021 12:34:41 +0000 (13:34 +0100)
libs/gtkutil/filechooser.cpp

index 2e7a921a11bf08431e86b8e09832e6fe5a461f5a..ac3d5a612e8573ef92562e136aa7ce7bbcae5f3a 100644 (file)
@@ -164,25 +164,23 @@ const char* file_dialog_show( ui::Window parent, bool open, const char* title, c
        gtk_window_set_position( dialog, GTK_WIN_POS_CENTER_ON_PARENT );
 
        // we expect an actual path below, if the path is 0 we might crash
-       if ( path != 0 && !string_empty( path ) ) {
+       if ( path != nullptr && !string_empty( path ) ) {
                ASSERT_MESSAGE( path_is_absolute( path ), "file_dialog_show: path not absolute: " << makeQuoted( path ) );
 
-               Array<char> new_path( strlen( path ) + 1 );
+               std::string new_path( path );
 
-               // copy path, replacing dir separators as appropriate
-               Array<char>::iterator w = new_path.begin();
-               for ( const char* r = path; *r != '\0'; ++r )
-               {
-                       *w++ = ( *r == '/' ) ? G_DIR_SEPARATOR : *r;
+               // replacing dir separators as appropriate
+               for ( char &c : new_path ) {
+                       if ( c == '/' ) {
+                              c = G_DIR_SEPARATOR;
+                       }
                }
                // remove separator from end of path if required
-               if ( *( w - 1 ) == G_DIR_SEPARATOR ) {
-                       --w;
+               if ( new_path.back() == G_DIR_SEPARATOR ) {
+                       new_path.pop_back();
                }
-               // 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...