cAudio 2.3.0
3d Audio Engine
Loading...
Searching...
No Matches
cAudioString.h
1// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
2// This file is part of the "cAudio Engine"
3// For conditions of distribution and use, see copyright notice in cAudio.h
4
5#pragma once
6
7#include "cAudioDefines.h"
8#include "cAudioPlatform.h"
9#include "cAudioMemory.h"
10#include "cSTLAllocator.h"
11
12#include <string>
13#include <stdlib.h>
14
15#ifdef CAUDIO_PLATFORM_WIN
16# include <direct.h>
17# include <io.h>
18#endif
19
20namespace cAudio
21{
22
23#if defined(UNICODE) || defined(_UNICODE)
24# define _CTEXT(x) L ## x
25# define cstrcmp wcscmp
26# define cAudioChar wchar_t
27# define cfopen(N, M) _wfopen((N).c_str(), L ## M)
28#else
29# define _CTEXT(x) x
30# define cstrcmp strcmp
31# define cAudioChar char
32# define cfopen(N, M) fopen(toUTF8(N), M)
33#endif
34
35#if CAUDIO_REROUTE_STRING_ALLOCATIONS == 1
36 typedef std::basic_string< cAudioChar, std::char_traits<cAudioChar>, cSTLAllocator<cAudioChar> > cAudioString;
37#else
38# if defined(UNICODE) || defined(_UNICODE)
39 typedef std::basic_string<cAudioChar> cAudioString;
40# else
41 typedef std::string cAudioString;
42# endif
43#endif
44
45
46#if defined(CAUDIO_PLATFORM_WIN)
47 static const char* toUTF8(const cAudioString& str)
48 {
49 static int id = 0;
50 static char buffer[8][1024];
51 id = ++id & 0x7;
52
53 int buff_size = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), (int)(str.size() < 1023 ? str.size() : 1023), buffer[id], 1023, 0, false);
54 buffer[id][buff_size] = 0;
55 buffer[id][1023] = 0;
56 return buffer[id];
57 }
58
59 static cAudioString fromUTF8(const char* str)
60 {
61 int str_len = (int)strlen(str);
62 int buf_size = MultiByteToWideChar(CP_UTF8, 0, str, str_len, 0, 0);
63 cAudioString s(buf_size, L'\0');
64 MultiByteToWideChar(CP_UTF8, 0, str, str_len, &s[0], buf_size);
65 return s;
66 }
67
68#else
69 inline const char* toUTF8(const cAudioString& str)
70 {
71 return str.c_str();
72 }
73
74 inline cAudioString fromUTF8(const char* str)
75 {
76 return cAudioString(str);
77 }
78#endif
79};
80
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:16