Re: Glib::ConvertError (or: I obviously still don't understand Glib::ustring)



On Saturday 29 October 2005 19:50, Matthias Kaeppler wrote:

[filename]

>      // open current directory
>      DirectoryHandle dir;
>      FileInfoOptions options =
> 	FILE_INFO_FOLLOW_LINKS |
> 	FILE_INFO_GET_MIME_TYPE |
> 	FILE_INFO_FORCE_FAST_MIME_TYPE;
>
>      dir.open(working_directory_.get_uri_string(), options);
>
>      Glib::ustring filename;
>      Glib::RefPtr<FileInfo> file_info;
>      bool file_exists = true;
>
>      // iterate over directory content
>      while (true)
>      {
> 	file_info = dir.read_next(file_exists);
> 	if (!file_exists)
> 	    break;
>
> 	try
> 	{
>              // the next line throws with the following reason:
>              // "Invalid byte sequence in conversion input"
>              // the file in question is called "tästfile"
>              // (note the umlaut)
> 	    filename = Glib::filename_to_utf8(file_info->get_name());
> 	    std::cout << filename << std::endl;
> 	}
> 	catch (const Glib::ConvertError& e)
> 	{
> 	    std::cerr << e.what() << std::endl;
> 	    exit(1);
> 	}
>
> 	if (filename == "." || filename == "/")
> 	    continue;
>
> 	File file (working_directory_);
> 	if (::is_directory(file_info))
> 	    file.append_path(filename);
> 	else
> 	    file.append_filename(filename);
>
> 	files_.push_back(file);
>      }
>
> I tried to replace filename_to_utf8() with locale_to_utf8() (I still
> don't get where the difference is, really, but I thought it was worth a
> try).

I do not use gnomemm, but either Gnome::Vfs::FileInfo::get_name() doesn't 
return the filename in the filename codeset for your locale (which is 
unlikely), or you did not name the file tästfile in your locale's filename 
codeset (more likely).  Probably you gave its name in UTF-8 and your filename 
codeset is ISO8859-15, or vice versa.  Remember that as far as Unix is 
concerned the file name is just a sequence of bytes.  It is for you to get 
the sequence right.

The filename codeset for a locale is usually the same as the text codeset for 
the locale, but can be different.

Why not just call it taestfile?

Chris




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]