nlib
Convert.h
[詳解]
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)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:163
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:178
UTF-8/UTF-16/UTF-32の文字列をUTF-8として渡すためのクラスです。
Definition: Convert.h:25
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
UTF-8/UTF-16/UTF-32の文字列をワイド文字列(UTF-16/UTF-32)として渡すためのクラスです。 ...
Definition: Convert.h:46
uint32_t nlib_utf32_t
char32_tが利用できる場合はchar32_tに、そうでない場合はuint32_tにtypedefされます。 ...
Definition: Platform.h:286
uint16_t nlib_utf16_t
char16_tが利用できる場合はchar16_tに、そうでない場合はuint16_tにtypedefされます。 ...
Definition: Platform.h:285
const char * c_str() noexcept
明示的にC文字列を返します。
Definition: Convert.h:37
ToWideObj(const wchar_t *wstr) noexcept
ワイド文字列を設定します。
Definition: Convert.h:49
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:99
ToUtf8Obj(const nlib_utf8_t *str) noexcept
UTF-8文字列を設定します。
Definition: Convert.h:30
const wchar_t * c_str() noexcept
明示的にワイド文字列を返します。
Definition: Convert.h:55
開発環境別の設定が書かれるファイルです。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:229
char nlib_utf8_t
charのtypedefです。文字列がUTF-8であることを示します。
Definition: Platform.h:300