Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Tamico

Pages: [1]
1
This helped me a lot, and it could be useful to someone. I've adapted the solution proposed on another forum post (here's a link).

Here's the solution I used:
// Takes sf::String (UTF-32) and returns std::string (UTF-8)
std::string to_std_string(const sf::String& original)
{
    // The final UTF-8 string
    std::string str;
    // Worst case scenario: 4 bytes per codepoint
    str.resize(original.getSize() * 4);
    std::string::iterator last = sf::Utf<32>::toUtf8( original.getData(),
        original.getData() + original.getSize(), str.begin() );
    str.resize(last - str.begin());
    return str;
}

This will take any sf::String containing unicode codepoint and pass it to a std::string that can be used to output to anywhere. You can even use this std::string for filenames.

NOTE: I've tested this with the main Linux distros (Debian, OpenSUSE, Arch, Fedora, etc.) and Windows XP/Vista/7. The behavior appears to be consistent, but it may not be that way for all machines.

You can set a unicode character by using its codepoint:
// Codepoint in decimal
sf::Uint32 unicode_char = 12354;
// Append unicode char to an sf::String
sf::String unicode_string += unicode_char;

This will create the character '0x3042' (or '12354' in decimal) which is the hiragana character 'あ'. For reference, here's a list of unicode characters along with their codepoint.

2
SFML projects / Simple Kana Editor
« on: June 13, 2015, 11:27:56 pm »
This is a (very simple) editor for katakana and hiragana. You can type in standard romaji (english representations of kana characters) and it will "translate" what you type on the fly.


More information is available at the Github repo, where you can download and build the project for yourself. You'll find instructions for building it on Windows and Linux. The code is freely available, so you're free to fork it or modify it any way you want.

There's no OSX build yet. I'm not familiar with OSX, but if you'd like, you can contribute by forking it and adding some _APPLE_ macros to get it to compile on OSX. You're not only free to do so, but it would be greatly appreciated! The only platform specific sources are main.cpp, savewindow.cpp, main.hpp, and savewindow.hpp (and potentially defines.h).

NOTE: This code does not follow any coding standard. A lot of it is sloppy. I know better now, but it's a nightmare to fix (Sorry!). Future projects will not be so sloppy.

I don't know how much more info to provide, but you can ask me any questions you might have. You can also try contacting me by email through Github.

Links:
- Github project page
- Download sources

EDIT: Fixed image.

3
System / Unable to free memory when using toAnsiString()
« on: October 06, 2013, 09:57:35 pm »
I'm having an issue when using toAnsiString() in conjunction with std::ofstream. The function runs fine until it returns, in which case it crashes.

Here's the minimal code:

#include <SFML/System.hpp>
#include <fstream>
#include <string>

int main()
{
        // You could replace OUTPUT/OUTPUT.txt with your existing home directory
        sf::String filepath = "OUTPUT/OUTPUT.txt";
       
        // I suspect this is what is causing problems
        std::string tempout = filepath.toAnsiString();
       
        std::ofstream fileoutput ( tempout.c_str() );
       
        if (fileoutput.is_open())
        {
                fileoutput << "Output";
        }
}

The text file is created and contains "Output", but the program crashes on exit.

Here is the setup I'm using:

OS: Wndows 7 (64-bit)
Graphics device: Intgrated Intel graphics
SFML: v2.1 standard release (dynamically linked)
Compiler: Visual C/C++ 2010 (32-bit) -- compiled directly from the command prompt

I've also run the code in WinDbg. I get this when main() returns:

1   HEAP[minimal.exe]: Invalid address specified to RtlFreeHeap( 00550000, 005A3808 )
2   (d28.1070): WOW64 breakpoint - code 4000001f (first chance)
3   First chance exceptions are reported before any exception handling.
4   This exception may be expected and handled.
5   ntdll32!RtlpBreakPointHeap+0x23:
6   77950574 cc              int     3


Any help is appreciated.

Pages: [1]