Skip to content

Commit

Permalink
utf8 2017-11-22 (e8de6037)
Browse files Browse the repository at this point in the history
Code extracted from:

    https://gitlab.kitware.com/third-party/utfcpp.git

at commit e8de6037bec6c3151e9df2c50555122acd850c2a (for/vtk).
  • Loading branch information
kwrobot authored and mathstuf committed Nov 22, 2017
1 parent 3090f6b commit 503e86c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.kitware.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ another source tree.
* Rename the namespace to not conflict with external copies.
* Add `.gitattributes` to pass VTK's commit checks.
* Fix shadowing warnings.
* Use `noexcept` rather than `throw()` to avoid warnings in VTK.
20 changes: 16 additions & 4 deletions utf8/checked.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ DEALINGS IN THE SOFTWARE.
#include "core.h"
#include <stdexcept>

#if __cplusplus >= 201103L
#define VTKUTF8_NOEXCEPT noexcept
#elif defined(_MSC_VER)
#if _MSC_VER >= 1900
#define VTKUTF8_NOEXCEPT noexcept
#else
#define VTKUTF8_NOEXCEPT throw()
#endif
#else
#define VTKUTF8_NOEXCEPT throw()
#endif

namespace vtk_utf8
{
// Base for the exceptions that may be thrown from the library
Expand All @@ -42,29 +54,29 @@ namespace vtk_utf8
uint32_t cp;
public:
invalid_code_point(uint32_t _cp) : cp(_cp) {}
virtual const char* what() const throw() { return "Invalid code point"; }
virtual const char* what() const VTKUTF8_NOEXCEPT { return "Invalid code point"; }
uint32_t code_point() const {return cp;}
};

class invalid_utf8 : public exception {
uint8_t u8;
public:
invalid_utf8 (uint8_t u) : u8(u) {}
virtual const char* what() const throw() { return "Invalid UTF-8"; }
virtual const char* what() const VTKUTF8_NOEXCEPT { return "Invalid UTF-8"; }
uint8_t utf8_octet() const {return u8;}
};

class invalid_utf16 : public exception {
uint16_t u16;
public:
invalid_utf16 (uint16_t u) : u16(u) {}
virtual const char* what() const throw() { return "Invalid UTF-16"; }
virtual const char* what() const VTKUTF8_NOEXCEPT { return "Invalid UTF-16"; }
uint16_t utf16_word() const {return u16;}
};

class not_enough_room : public exception {
public:
virtual const char* what() const throw() { return "Not enough space"; }
virtual const char* what() const VTKUTF8_NOEXCEPT { return "Not enough space"; }
};

/// The library API - functions intended to be called by the users
Expand Down

0 comments on commit 503e86c

Please sign in to comment.