-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transcode Windows paths to current code page
This is an alternative approach to using the std::wstring versions of exiv2 methods that are not available in v0.28.x (see Exiv2/exiv2#2637). It should also allow non ascii paths to be used when libexiv2 has been compiled without wstring methods enabled. The proper approach is to set the Windows code page to utf-8, but this probably won't work on old Windows, and it's not clear how to do it for a Python application. Instead we transcode paths from utf-8 to the current code page, which could fail.
- Loading branch information
1 parent
c1d4aa6
commit 1d499ed
Showing
11 changed files
with
244 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// python-exiv2 - Python interface to libexiv2 | ||
// http://github.com/jim-easterbrook/python-exiv2 | ||
// Copyright (C) 2023 Jim Easterbrook [email protected] | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
|
||
// If exiv2's wstring methods are available then use them! | ||
#ifdef EXV_UNICODE_PATH | ||
%include "std_wstring.i" | ||
#endif | ||
|
||
// Function to convert utf-8 string to current code page | ||
%fragment("transcode_path", "header") { | ||
static void transcode_path(std::string *path) { | ||
%#ifdef _WIN32 | ||
UINT acp = GetACP(); | ||
if (acp == CP_UTF8) | ||
return; | ||
// Convert utf-8 path to active code page, via widechar version | ||
int wide_len = MultiByteToWideChar(CP_UTF8, 0, &(*path)[0], -1, NULL, 0); | ||
std::wstring wide_str; | ||
wide_str.resize(wide_len); | ||
if (MultiByteToWideChar(CP_UTF8, 0, &(*path)[0], -1, | ||
&wide_str[0], (int)wide_str.size()) >= 0) { | ||
int new_len = WideCharToMultiByte(acp, 0, &wide_str[0], -1, | ||
NULL, 0, NULL, NULL); | ||
path->resize(new_len); | ||
WideCharToMultiByte(acp, 0, &wide_str[0], -1, | ||
&(*path)[0], (int)path->size(), NULL, NULL); | ||
} | ||
%#endif | ||
}; | ||
} | ||
|
||
// Macro to convert Windows paths from utf-8 to current code page | ||
%define WINDOWS_PATH(signature) | ||
#ifndef EXV_UNICODE_PATH | ||
%typemap(check, fragment="transcode_path") signature { | ||
transcode_path($1); | ||
} | ||
#endif | ||
%enddef // WINDOWS_PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.