On Tue, Apr 28, 2009 at 2:51 PM, Peter Kasting <[email protected]> wrote:

> On Tue, Apr 28, 2009 at 2:48 PM, Greg Spencer <[email protected]> wrote:
>
>> So, I was unable to find the conversion utilities in base that do the
>> conversion to/from UTF8.  What are they called?  If I missed them (and I
>> looked for a while before I gave up), then maybe they need to be more
>> prominent?
>>
>
> See base/string_util.h, UTF8ToUTF16() etc.
>

Yes, but those are generic string conversions, and so to convert a FilePath
to UTF16 on all platforms, my code has to look something like:

--
FilePath path(FILE_PATH_LITERAL("Foo.bar"));
collada::fstring collada_path; // a UTF16 path.
#if defined(OS_WIN)
  collada_path = path.value();
#elif defined(OS_MACOSX)
  collada_path = UTF8ToUTF16(path.value());
#elif defined(OS_LINUX)
  // (or whatever this linux flavor uses for a filename encoding.)
  collada_path = Latin1ToUTF16(path.value());
#endif
--

This seems like code that belongs in FilePath because it knows exactly what
the filename encoding would be on each platform.

Yes, partly because including dedicated helpers like this makes it sound as
> if the class is somehow special-cased or fastpathed to deal better with
> these than a generic converter would be.
>

But it can.  For instance, on the Mac, we know that filenames are UTF8
encoded.  We have not such guarantee on Linux, even though they both use a
char* format in FilePath.  If FilePath were doing the conversion, then it
could be very picky about doing the conversion properly on each platform,
because converting a Latin-1 string to a wide char using a UTF8 codec may
end up with some strange results.

The other argument is simply that converting utf8 to utf16 is a generic sort
> of functionality that belongs in base/ or another similar general-purpose
> location, rather than specifically in FilePath.
>

And the implementation in FilePath would be using those generic functions,
but it would be using them (or not) as applied to the specific platform it
is compiled on, whereas the conversion routines don't know anything about
FilePath's platform specific semantics.

-Greg.

--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: [email protected] 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to