login about faq

When I use CkStringArray's LoadFile or LoadFromFile2 methods to load the content of a text file where the path contains Danish, Swedish and most likely characters from other languages, it fails with the following:

    DllDate: Dec 18 2012
    UnlockPrefix: XXXXXXXXXXXXXX
    Architecture: Little Endian; 32-bit
    Language: Visual C++ 11.0
    VerboseLogging: 0
          Failed to open file (2)
          localFilePath: D:\test\llebrd\test.txt
          currentWorkingDirectory: D:\Projects\TestProject
          osErrorInfo: The system cannot find the path specified.
          localWindowsFilePath: D:\test\llebrd\test.txt

The path in question contains the letter 'ø' as in øllebrød: D:\test\øllebrød\test.txt. If I use CkString's LoadFile method it appears to work fine.

asked May 07 '13 at 11:13

roan98dk's gravatar image


edited May 07 '13 at 11:14

I'll provide a new build for testing ASAP...

(May 07 '13 at 18:20) chilkat ♦♦

As long as you can confirm this I do not require a pre-release build. Since I have to make too many other code modifications in order to test a pre-release, I prefer to only implement the final release. I trust that your fix will work :-)

(May 07 '13 at 18:24) roan98dk

I tested but did not find a problem.

Maybe this is the problem: When a "const char " is passed to a Chilkat method, the default interpretation is that the bytes are characters represented in the ANSI encoding. If you are passing a "const char " that contains utf-8 encoded, bytes, you must first tell the object instance that it should interpret incoming "const char *" args as utf-8. You would do this by setting the "Utf8" property (which is common to all Chilkat C++ classes) to true. For example:

CkString strPath;
// Passing ANSI here because it's a string literal.

CkStringArray sa; sa.put_Utf8(true); // Passing the utf-8 representation of the path to LoadFromFile: bool success = sa.LoadFromFile(strPath.getUtf8());

See: http://www.cknotes.com/?p=98


answered May 08 '13 at 11:06

chilkat's gravatar image

chilkat ♦♦

I must have misinterpreted the meaning. I knew that sa.put_Utf8(true) meant that sa.Append("some string") would expect "some string" to be utf-8 encoded, but I did not realize that this would obviously also impact sa.LoadFromFile("some path").

(May 08 '13 at 13:06) roan98dk

I just confirmed that converting the input path from ANSI to utf-8 solves the problem. Thanks and I apologize for the inconvenience.

(May 08 '13 at 15:47) roan98dk

It's no problem. :)

Just for clarification (and I think you already know this) -- the put_Utf8(true) is not telling the CkStringArray how to interpret the bytes within the file you are opening -- it's telling it how to interpret the bytes of the "const char *" passed for the file path.

The LoadFromFile method assumes the file contains ANSI chars. If not, then you would instead call LoadFromFile2(filepath,charset), where the 2nd arg can be any charset.

(May 08 '13 at 15:54) chilkat ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: May 07 '13 at 11:13

Seen: 2,379 times

Last updated: May 08 '13 at 15:54

powered by OSQA