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