Skip to content

Commit

Permalink
Introduce UTF_CPP_CPLUSPLUS macro.
Browse files Browse the repository at this point in the history
Let the users set the C++ standard version they want to support.
  • Loading branch information
nemtrif committed Jun 30, 2019
1 parent 088dd3a commit b1002fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -94,7 +94,11 @@ With a more modern compiler, the same operation would look like:
```
If `__cplusplus` macro points to a C++ 11 or later, the library exposes API that takes into
account C++ standard Unicode strings and move semantics. With an older compiler, it is still
possible to use the same functionality, just in a little less convenient way.
possible to use the same functionality, just in a little less convenient way

In case you do not trust the `__cplusplus` macro or, for instance, do not want to include
the C++ 11 helper functions even with a modern compiler, define `UTF_CPP_CPLUSPLUS` macro
before including `utf8.h` and assign it a value for the standard you want to use - the values are the same as for the `__cplusplus` macro. This can be also useful with compilers that are conservative in setting the `__cplusplus` macro even if they have a good support for a recent standard edition - Microsoft's Visual C++ is one example.

### Checking if a file contains valid UTF-8 text

Expand Down
10 changes: 9 additions & 1 deletion source/utf8.h
Expand Up @@ -31,7 +31,15 @@ DEALINGS IN THE SOFTWARE.
#include "utf8/checked.h"
#include "utf8/unchecked.h"

#if __cplusplus >= 201103L // C++ 11 or later
// Determine whether to include C++ 11 specific header
// If the user defines UTF_CPP_CPLUSPLUS, use that.
// Otherwise, trust the unreliable predefined macro __cplusplus

#if !defined UTF_CPP_CPLUSPLUS
#define UTF_CPP_CPLUSPLUS __cplusplus
#endif

#if UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later
#include "utf8/cpp11.h"
#endif // C++ 11 or later

Expand Down

0 comments on commit b1002fd

Please sign in to comment.