nlib
Convert.h
Go to the documentation of this file.
1 
2 /*---------------------------------------------------------------------------*
3 
4  Project: CrossRoad
5  Copyright (C)2012-2016 Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12 
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 char* 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 char*() 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 char* buf_;
42  bool is_internal_alloc_;
44 };
45 
47  public:
48  explicit ToWideObj(const char* 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:158
#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:173
Class to use to pass a UTF-8, UTF-16, or UTF-32 string as UTF-8.
Definition: Convert.h:25
ToUtf8Obj(const char *str) noexcept
Sets the UTF-8 string.
Definition: Convert.h:30
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:87
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: Config.h:552
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: Config.h:551
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
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:224