Celestia

Форк
0
/
winutil.cpp 
41 строка · 1.1 Кб
1
// winutil.cpp
2
//
3
// Copyright (C) 2019-present, Celestia Development Team
4
// Copyright (C) 2002, Chris Laurel <claurel@shatters.net>
5
//
6
// Miscellaneous useful Windows-related functions.
7
//
8
// This program is free software; you can redistribute it and/or
9
// modify it under the terms of the GNU General Public License
10
// as published by the Free Software Foundation; either version 2
11
// of the License, or (at your option) any later version.
12

13
#include "winutil.h"
14

15
#include <windows.h>
16

17
namespace celestia::util
18
{
19

20
std::string
21
WideToUTF8(std::wstring_view ws)
22
{
23
    if (ws.empty())
24
        return {};
25

26
    // get a converted string length
27
    const auto srcLen = static_cast<int>(ws.size());
28
    int len = WideCharToMultiByte(CP_UTF8, 0, ws.data(), srcLen, nullptr, 0, nullptr, nullptr);
29
    if (len <= 0)
30
        return {};
31

32
    std::string out(static_cast<std::string::size_type>(len), '\0');
33
    len = WideCharToMultiByte(CP_UTF8, 0, ws.data(), srcLen, out.data(), len, nullptr, nullptr);
34
    if (len <= 0)
35
        return {};
36

37
    out.resize(static_cast<std::size_t>(len));
38
    return out;
39
}
40

41
} // end namespace celestia::util
42

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.