Mercurial > love-experiments
annotate src/common/utf8.cpp @ 1448:108ee2e81f65 default tip
Fix a case typo, imageData.h -> ImageData.h
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sat, 18 Jan 2014 13:57:44 +0100 |
| parents | b7f097053d74 |
| children |
| rev | line source |
|---|---|
| 1096 | 1 /** |
|
1282
b7f097053d74
Updated copyright text for the new year
Alex Szpakowski <slime73@gmail.com>
parents:
1096
diff
changeset
|
2 * Copyright (c) 2006-2013 LOVE Development Team |
| 1096 | 3 * |
| 4 * This software is provided 'as-is', without any express or implied | |
| 5 * warranty. In no event will the authors be held liable for any damages | |
| 6 * arising from the use of this software. | |
| 7 * | |
| 8 * Permission is granted to anyone to use this software for any purpose, | |
| 9 * including commercial applications, and to alter it and redistribute it | |
| 10 * freely, subject to the following restrictions: | |
| 11 * | |
| 12 * 1. The origin of this software must not be misrepresented; you must not | |
| 13 * claim that you wrote the original software. If you use this software | |
| 14 * in a product, an acknowledgment in the product documentation would be | |
| 15 * appreciated but is not required. | |
| 16 * 2. Altered source versions must be plainly marked as such, and must not be | |
| 17 * misrepresented as being the original software. | |
| 18 * 3. This notice may not be removed or altered from any source distribution. | |
| 19 **/ | |
| 20 | |
| 21 #include "utf8.h" | |
| 22 | |
| 23 #ifdef LOVE_WINDOWS | |
| 24 | |
| 25 namespace love | |
| 26 { | |
| 27 | |
| 28 std::string to_utf8(LPCWSTR wstr) | |
| 29 { | |
| 30 size_t wide_len = wcslen(wstr)+1; | |
| 31 | |
| 32 // Get size in UTF-8. | |
| 33 int utf8_size = WideCharToMultiByte(CP_UTF8, 0, wstr, wide_len, 0, 0, 0, 0); | |
| 34 | |
| 35 char *utf8_str = new char[utf8_size]; | |
| 36 | |
| 37 // Convert to UTF-8. | |
| 38 int ok = WideCharToMultiByte(CP_UTF8, 0, wstr, wide_len, utf8_str, utf8_size, 0, 0); | |
| 39 | |
| 40 std::string ret; | |
| 41 if (ok) | |
| 42 ret = utf8_str; | |
| 43 | |
| 44 delete[] utf8_str; | |
| 45 return ret; | |
| 46 } | |
| 47 | |
| 48 void replace_char(std::string &str, char find, char replace) | |
| 49 { | |
| 50 int length = str.length(); | |
| 51 | |
| 52 for (int i = 0; i<length; i++) | |
| 53 { | |
| 54 if (str[i] == find) | |
| 55 str[i] = replace; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 } // love | |
| 60 | |
| 61 #endif // LOVE_WINDOWS |
