From bada6666c70977a058755ccf232e7d67b24adeed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 23 Jul 2014 15:21:29 +0200 Subject: New upstream release --- libxsd-frontend/xsd-frontend/types.cxx | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 libxsd-frontend/xsd-frontend/types.cxx (limited to 'libxsd-frontend/xsd-frontend/types.cxx') diff --git a/libxsd-frontend/xsd-frontend/types.cxx b/libxsd-frontend/xsd-frontend/types.cxx new file mode 100644 index 0000000..49faf92 --- /dev/null +++ b/libxsd-frontend/xsd-frontend/types.cxx @@ -0,0 +1,61 @@ +// file : xsd-frontend/types.cxx +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include // std::mbstowcs + +#include + +namespace XSDFrontend +{ + // NonRepresentable + // + char const* NonRepresentable:: + what () const throw () + { + return "character is not representable in the narrower encoding"; + } + + // StringTemplate + // + + // Specialization for char to wchar_t conversion. + // + template <> + void StringTemplate:: + from_narrow (char const* s) + { + size_type size (std::mbstowcs (0, s, 0) + 1); + + // I dare to change the guts! + // + resize (size - 1); + + wchar_t* p (const_cast (data ())); + + std::mbstowcs (p, s, size); + } + + // Specialization for wchar_t to char conversion. + // + template <> + StringTemplate StringTemplate:: + to_narrow () const + { + size_type size (std::wcstombs (0, c_str (), 0)); + + if (size == size_type (-1)) + throw NonRepresentable (); + + // I dare to change the guts! + // + StringTemplate r; + r.resize (size); + + char* p (const_cast (r.data ())); + + std::wcstombs (p, c_str (), size + 1); + + return r; + } +} -- cgit v1.2.3