File: string_utils.h

package info (click to toggle)
megaglest 3.13.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 13,416 kB
  • sloc: cpp: 144,271; ansic: 11,861; sh: 3,233; perl: 1,904; python: 1,751; objc: 142; asm: 42; makefile: 22
file content (71 lines) | stat: -rw-r--r-- 1,893 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*  Portions taken from:
    Copyright (C) 2005  Roland BROCHARD

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA*/

#ifndef _SHARED_UTIL_W_STRING_H__
#define _SHARED_UTIL_W_STRING_H__

#include <string>
#include "data_types.h"

#ifdef __MINGW32__
typedef unsigned char byte;
#endif


#ifndef WIN32
using Shared::Platform::byte;
#endif

using namespace Shared::Platform;

namespace Shared { namespace Util {

	/*!
        ** \brief Convert a string from ASCII to UTF8
        ** \param s The string to convert
        ** \return A new Null-terminated String (must be deleted with the keyword `delete[]`), even if s is NULL
    */
    char* ConvertToUTF8(const char* s);

    char* ConvertFromUTF8(const char* str);

	/*!
	** \brief Convert an UTF-8 String into a WideChar String
	*/
	struct WString
	{
	public:
		WString(const char* s);
		WString(const std::string& str);

		void fromUtf8(const char* s, size_t length);
		const wchar_t* cw_str() const {return pBuffer;}

	private:
		wchar_t pBuffer[8096];
	};

	void strrev(char *p);
	void strrev_utf8(char *p);
	void strrev_utf8(std::string &p);
	bool is_string_all_ascii(std::string str);

	int getUTF8_Width(const char *str);

}}

#endif // _SHARED_UTIL_W_STRING_H__