Commit a6f88881 authored by Adam Reichold's avatar Adam Reichold Committed by Albert Astals Cid

Put (optional) usage of codecvt behind a configure check s.t. we at least...

Put (optional) usage of codecvt behind a configure check s.t. we at least compile even if we do not properly handle the unicode page label.
parent 65c8bc1e
Pipeline #5133 passed with stage
in 6 minutes and 29 seconds
......@@ -4,6 +4,7 @@
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckFunctionExists)
......@@ -17,6 +18,7 @@ check_include_files(stdlib.h HAVE_STDLIB_H)
check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
check_include_files(sys/stat.h HAVE_SYS_STAT_H)
check_include_files(unistd.h HAVE_UNISTD_H)
check_include_file_cxx(codecvt HAVE_CODECVT)
check_function_exists(fseek64 HAVE_FSEEK64)
check_function_exists(fseeko HAVE_FSEEKO)
......
......@@ -117,6 +117,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H 1
/* Define to 1 if you have the <codecvt> header file. */
#cmakedefine HAVE_CODECVT
/* Define to 1 if you have a big endian machine */
#cmakedefine WORDS_BIGENDIAN 1
......
......@@ -14,20 +14,19 @@
/* http://mathworld.wolfram.com/RomanNumerals.html */
#include "config.h"
#ifdef HAVE_CODECVT
#include <locale>
#include <codecvt>
#endif
#include "goo/GooString.h"
#include "Error.h"
static std::pair<int,bool> fromDecimal(const char *const begin, const char *const end, const bool unicode) {
if (!unicode) {
char *parsed;
const int number = std::strtol(begin, &parsed, 10);
if (parsed >= end) {
return std::make_pair(number, true);
}
} else {
#ifdef HAVE_CODECVT
if (unicode) {
std::wstring_convert<std::codecvt_utf16<wchar_t>> converter;
const auto str = converter.from_bytes(begin, end);
......@@ -43,8 +42,13 @@ static std::pair<int,bool> fromDecimal(const char *const begin, const char *cons
return std::make_pair(number, true);
}
}
#else
(void)unicode;
#endif
return std::make_pair(0, false);
char *parsed;
const int number = std::strtol(begin, &parsed, 10);
return std::make_pair(number, parsed >= end);
}
static int fromRoman(const char *buffer) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment