nlib
Convert.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_UNICODE_CONVERT_H_
17 #define INCLUDE_NN_NLIB_UNICODE_CONVERT_H_
18 
19 #include "nn/nlib/Config.h"
20 
21 // functions below may be deprecated in the future
22 NLIB_NAMESPACE_BEGIN
23 namespace unicode {
24 
26  public:
27  explicit ToUtf8Obj(const wchar_t* wstr) NLIB_NOEXCEPT;
28  explicit ToUtf8Obj(const nlib_utf16_t* utf16str) NLIB_NOEXCEPT;
29  explicit ToUtf8Obj(const nlib_utf32_t* utf32str) NLIB_NOEXCEPT;
30  explicit ToUtf8Obj(const nlib_utf8_t* str) NLIB_NOEXCEPT {
31  // does not work if the encoding is not UTF-8.
32  buf_ = str;
33  is_internal_alloc_ = false;
34  }
36  operator const nlib_utf8_t*() NLIB_NOEXCEPT { return buf_ ? buf_ : ""; }
37  const char* c_str() NLIB_NOEXCEPT { return buf_ ? buf_ : ""; }
38  NLIB_SAFE_BOOL(ToUtf8Obj, buf_ != NULL)
39 
40  private:
41  const nlib_utf8_t* buf_;
42  bool is_internal_alloc_;
44 };
45 
47  public:
48  explicit ToWideObj(const nlib_utf8_t* str) NLIB_NOEXCEPT;
49  explicit ToWideObj(const wchar_t* wstr) NLIB_NOEXCEPT {
50  buf_ = wstr;
51  is_internal_alloc_ = false;
52  }
54  operator const wchar_t*() NLIB_NOEXCEPT { return buf_ ? buf_ : L""; }
55  const wchar_t* c_str() NLIB_NOEXCEPT { return buf_ ? buf_ : L""; }
56  NLIB_SAFE_BOOL(ToWideObj, buf_ != NULL)
57 
58  private:
59  const wchar_t* buf_;
60  bool is_internal_alloc_;
62 };
63 
64 } // namespace unicode
65 NLIB_NAMESPACE_END
66 
67 #endif // INCLUDE_NN_NLIB_UNICODE_CONVERT_H_
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:163
#define NLIB_SAFE_BOOL(class_name, exp)
Defines a safe operator bool function in the class. Uses the C++11 explicit bool if it is available f...
Definition: Config.h:178
Class to use to pass a UTF-8, UTF-16, or UTF-32 string as UTF-8.
Definition: Convert.h:25
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
Class used to pass a UTF-8, UTF-16, or UTF-32 string as a wide character (UTF-16/UTF-32) string...
Definition: Convert.h:46
uint32_t nlib_utf32_t
Uses typedef to define as char32_t if that can be used. If not, it uses typedef to define as uint32_t...
Definition: Platform.h:286
uint16_t nlib_utf16_t
Uses typedef to define as char16_t if that can be used. If not, it uses typedef to define as uint16_t...
Definition: Platform.h:285
const char * c_str() noexcept
Explicitly returns a C string.
Definition: Convert.h:37
ToWideObj(const wchar_t *wstr) noexcept
Sets a wide character string.
Definition: Convert.h:49
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
ToUtf8Obj(const nlib_utf8_t *str) noexcept
Sets the UTF-8 string.
Definition: Convert.h:30
const wchar_t * c_str() noexcept
Explicitly returns a wide string.
Definition: Convert.h:55
A file that contains the configuration information for each development environment.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
char nlib_utf8_t
Defines char with a typedef. Indicates that it is a UTF-8 string.
Definition: Platform.h:300