Merge pull request #1961 from akruphi/master
[far2l.git] / WinPort / src / APIPrintFormat.cpp
blob020a0a3c4278d604407a0add67ca2b6e64a8b579
1 #include <mutex>
2 #include "WinPort.h"
3 #include "WinPortHandle.h"
4 #include "PathHelpers.h"
6 SHAREDSYMBOL int vswprintf_ws2ls(wchar_t * ws, size_t len, const wchar_t * format, va_list arg )
8 std::wstring converted_format;
9 for (bool percent = false; *format; ++format) {
10 if (percent) {
11 if (*format==L's') {
12 if (!converted_format.empty()) {
13 if (converted_format.back() == L'w')
14 converted_format.back() = L'l';
15 else if (converted_format.back() == L'h')
16 converted_format.pop_back();
17 else
18 converted_format+= L'l';
19 } else
20 converted_format+= L'l';
22 if (wcschr(L"diouxXeEfFgGcCsSpnm%", *format)) {
23 percent = false;
25 } else if (*format==L'%') {
26 percent = true;
28 converted_format+= *format;
31 return vswprintf(ws, len, converted_format.c_str(), arg );
35 SHAREDSYMBOL int swprintf_ws2ls (wchar_t* ws, size_t len, const wchar_t* format, ...)
37 va_list arg;
38 va_start(arg,format);
39 int r = vswprintf_ws2ls(ws, len, format, arg );
40 va_end(arg);
41 return r;