[Ttssh2-commit] [8685] codeconvにwcクラスを追加

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2020年 4月 12日 (日) 00:53:28 JST


Revision: 8685
          https://osdn.net/projects/ttssh2/scm/svn/commits/8685
Author:   zmatsuo
Date:     2020-04-12 00:53:28 +0900 (Sun, 12 Apr 2020)
Log Message:
-----------
codeconvにwcクラスを追加

- wchar_t 文字列を保持するクラス

Modified Paths:
--------------
    trunk/teraterm/common/codeconv.cpp
    trunk/teraterm/common/codeconv.h

-------------- next part --------------
Modified: trunk/teraterm/common/codeconv.cpp
===================================================================
--- trunk/teraterm/common/codeconv.cpp	2020-04-11 15:53:18 UTC (rev 8684)
+++ trunk/teraterm/common/codeconv.cpp	2020-04-11 15:53:28 UTC (rev 8685)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018-2019 TeraTerm Project
+ * Copyright (C) 2018-2020 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -1269,3 +1269,139 @@
 		obj.tstr_ = NULL;
 	}
 }
+
+//////////////////////////////////////////////////////////////////////////////
+
+wc::wc()
+{
+	tstr_ = NULL;
+}
+
+wc::wc(const char *strA)
+{
+	tstr_ = NULL;
+	assign(strA, CP_ACP);
+}
+
+wc::wc(const char *strA, int code_page)
+{
+	tstr_ = NULL;
+	assign(strA, code_page);
+}
+
+wc::wc(const wchar_t *strW)
+{
+	tstr_ = NULL;
+	assign(strW);
+}
+
+wc::wc(const wc &obj)
+{
+	tstr_ = NULL;
+	copy(obj);
+}
+
+#if defined(MOVE_CONSTRUCTOR_ENABLE)
+wc::wc(wc &&obj) noexcept
+{
+	tstr_ = NULL;
+	move(obj);
+}
+#endif
+
+
+wc::~wc()
+{
+	if (tstr_ != NULL) {
+		free(tstr_);
+	}
+}
+
+wc& wc::operator=(const char *strA)
+{
+	assign(strA, CP_ACP);
+	return *this;
+}
+
+wc& wc::operator=(const wchar_t *strW)
+{
+	assign(strW);
+	return *this;
+}
+
+wc &wc::operator=(const wc &obj)
+{
+	copy(obj);
+	return *this;
+}
+
+#if defined(MOVE_CONSTRUCTOR_ENABLE)
+wc& wc::operator=(wc &&obj) noexcept
+{
+	move(obj);
+	return *this;
+}
+#endif
+
+wc wc::fromUtf8(const char *strU8)
+{
+	wchar_t *strW = _MultiByteToWideChar(strU8, 0, CP_UTF8, NULL);
+	wc _wc = strW;
+	free(strW);
+	return _wc;
+}
+
+// void\x82Ȃ\xB5\x82\xAA\x88\xEA\x94ʓI\x82Ǝv\x82\xED\x82\xEA\x82邪\x81A
+// VS2005\x82Ń\x8A\x83\x93\x83N\x83G\x83\x89\x81[\x82\xAA\x8Fo\x82Ă\xB5\x82܂\xA4\x82\xBD\x82\xDF void \x92lj\xC1
+wc::operator const wchar_t *(void) const
+{
+	return cstr();
+}
+
+const wchar_t *wc::cstr() const
+{
+	if (tstr_ == NULL) {
+		return L"";
+	}
+	return tstr_;
+}
+
+void wc::assign(const char *strA, int code_page)
+{
+	if (tstr_ != NULL) {
+		free(tstr_);
+	}
+	wchar_t *strW = _MultiByteToWideChar(strA, 0, code_page, NULL);
+	if (strW != NULL) {
+		tstr_ = strW;
+	} else {
+		tstr_ = NULL;
+	}
+}
+
+void wc::assign(const wchar_t *strW)
+{
+	if (tstr_ != NULL) {
+		free(tstr_);
+	}
+	tstr_ = _wcsdup(strW);
+}
+
+void wc::copy(const wc &obj)
+{
+	if (tstr_ != NULL) {
+		free(tstr_);
+	}
+	tstr_ = _wcsdup(obj.tstr_);
+}
+
+void wc::move(wc &obj)
+{
+	if (this != &obj) {
+		if (tstr_ != NULL) {
+			free(tstr_);
+		}
+		tstr_ = obj.tstr_;
+		obj.tstr_ = NULL;
+	}
+}

Modified: trunk/teraterm/common/codeconv.h
===================================================================
--- trunk/teraterm/common/codeconv.h	2020-04-11 15:53:18 UTC (rev 8684)
+++ trunk/teraterm/common/codeconv.h	2020-04-11 15:53:28 UTC (rev 8685)
@@ -150,4 +150,35 @@
 	void copy(const tc &obj);
 	void move(tc &obj);
 };
+
+class wc
+{
+public:
+	wc();
+	wc(const char *strA);
+	wc(const char *strA, int code_page);
+	wc(const wchar_t *strW);
+	wc(const wc &obj);
+#if defined(MOVE_CONSTRUCTOR_ENABLE)
+	wc(wc &&obj) noexcept;
 #endif
+	~wc();
+	wc& operator=(const char *strA);
+	wc& operator=(const wchar_t *strW);
+	wc& operator=(const wc &obj);
+#if defined(MOVE_CONSTRUCTOR_ENABLE)
+	wc& operator=(wc &&obj) noexcept;
+#endif
+	static wc fromUtf8(const char *strU8);
+	operator const wchar_t *() const;
+	const wchar_t *cstr() const;
+	operator const char *() const;
+//	const char *cstr() const;
+private:
+	wchar_t *tstr_;
+	void assign(const char *strA, int code_page);
+	void assign(const wchar_t *strW);
+	void copy(const wc &obj);
+	void move(wc &obj);
+};
+#endif


Ttssh2-commit メーリングリストの案内
Back to archive index