Sha256: e7fb4ff500af89047e151d41b278b5cac12be7e170af6bce099d82008c5e6a4f

Contents?: true

Size: 1.51 KB

Versions: 12

Compression:

Stored size: 1.51 KB

Contents

#include <Gosu/Platform.hpp>
#if defined(GOSU_IS_MAC)

#import <Gosu/Utility.hpp>
#import <Foundation/Foundation.h>
#import <stdexcept>
#import <vector>

#ifdef GOSU_IS_IPHONE
std::wstring Gosu::utf8_to_wstring(const std::string& s)
{
    if (s.empty()) {
        return std::wstring();
    }
    
    NSString* string = [NSString stringWithUTF8String:s.c_str()];
    std::vector<wchar_t> buffer(s.size());
    NSUInteger buffer_size;
    if (![string getBytes:&buffer[0]
                maxLength:buffer.size() * sizeof(wchar_t)
               usedLength:&buffer_size
                 encoding:NSUTF32LittleEndianStringEncoding
                  options:0
                    range:NSMakeRange(0, string.length)
           remainingRange:nullptr]) {
        throw std::runtime_error("String " + s + " could not be converted to UTF-32");
    }
    return std::wstring(&buffer[0], &buffer[0] + buffer_size / sizeof(wchar_t));
}

std::string Gosu::wstring_to_utf8(const std::wstring& ws)
{
    if (ws.empty()) return std::string();

    @autoreleasepool {
        NSString* string = [[NSString alloc] initWithBytes:ws.data()
                                                    length:ws.size() * sizeof(wchar_t)
                                                  encoding:NSUTF32LittleEndianStringEncoding];
        return string.UTF8String ?: std::string();
    }
}
#endif

std::string Gosu::language()
{
    @autoreleasepool {
        NSString* language = [NSLocale preferredLanguages][0];
        return language.UTF8String ?: "en";
    }
}

#endif

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gosu-0.12.1 src/UtilityApple.cpp
gosu-0.12.0 src/UtilityApple.cpp
gosu-0.11.4.pre3 src/UtilityApple.cpp
gosu-0.11.4.pre2 src/UtilityApple.cpp
gosu-0.11.4.pre1 src/UtilityApple.cpp
gosu-0.11.3.1 src/UtilityApple.cpp
gosu-0.11.3 src/UtilityApple.cpp
gosu-0.11.3.pre1 src/UtilityApple.cpp
gosu-0.11.2 src/UtilityApple.cpp
gosu-0.11.1 src/UtilityApple.cpp
gosu-0.11.1.pre1 src/UtilityApple.cpp
gosu-0.11.0 src/UtilityApple.cpp