File: libbfio_system_string.h

package info (click to toggle)
libewf 20100226-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 6,840 kB
  • ctags: 2,937
  • sloc: ansic: 100,745; sh: 10,115; makefile: 533
file content (174 lines) | stat: -rw-r--r-- 7,418 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
 * System character type string functions
 *
 * Copyright (c) 2006-2009, Joachim Metz <forensics@hoffmannbv.nl>,
 * Hoffmann Investigations.
 *
 * Refer to AUTHORS for acknowledgements.
 *
 * This software is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this software.  If not, see <http://www.gnu.org/licenses/>.
 */

#if !defined( _LIBBFIO_SYSTEM_STRING_H )
#define _LIBBFIO_SYSTEM_STRING_H

#include <common.h>
#include <narrow_string.h>
#include <types.h>
#include <wide_string.h>

#include "libbfio_libuna.h"

#if defined( _cplusplus )
extern "C" {
#endif

/* Detect if the code is being compiled with Windows Unicode support
 */
#if defined( WINAPI ) && ( defined( _UNICODE ) || defined( UNICODE ) )
#define LIBBFIO_HAVE_WIDE_SYSTEM_CHARACTER		1
#endif

#if defined( LIBBFIO_HAVE_WIDE_SYSTEM_CHARACTER )

typedef wchar_t libbfio_system_character_t;

#define PRIc_LIBBFIO_SYSTEM	"lc"
#define PRIs_LIBBFIO_SYSTEM	"ls"

/* Intermediate version of the macro required
 * for correct evaluation predefined string
 */
#define _LIBBFIO_SYSTEM_STRING_INTERMEDIATE( string ) \
	L ## string

#define _LIBBFIO_SYSTEM_STRING( string ) \
	_LIBBFIO_SYSTEM_STRING_INTERMEDIATE( string )

#define libbfio_system_string_copy( destination, source, size ) \
	wide_string_copy( destination, source, size )

#define libbfio_system_string_length( string ) \
	wide_string_length( string )

/* The wide character string type contains UTF-32
 */
#if SIZEOF_WCHAR_T == 4

/* narrow string conversion functions
 */
#define libbfio_system_string_size_from_narrow_string( narrow_string, narrow_string_size, system_string_size, error ) \
	libuna_utf32_string_size_from_utf8( (libuna_utf8_character_t *) narrow_string, narrow_string_size, system_string_size, error )

#define libbfio_system_string_copy_from_narrow_string( system_string, system_string_size, narrow_string, narrow_string_size, error ) \
	libuna_utf32_string_copy_from_utf8( (libuna_utf32_character_t *) system_string, system_string_size, (libuna_utf8_character_t *) narrow_string, narrow_string_size, error )

#define narrow_string_size_from_libbfio_system_string( system_string, system_string_size, narrow_string_size, error ) \
	libuna_utf8_string_size_from_utf32( (libuna_utf32_character_t *) system_string, system_string_size, narrow_string_size, error )

#define narrow_string_copy_from_libbfio_system_string( narrow_string, narrow_string_size, system_string, system_string_size, error ) \
	libuna_utf8_string_copy_from_utf32( (libuna_utf8_character_t *) narrow_string, narrow_string_size, (libuna_utf32_character_t *) system_string, system_string_size, error )

/* The wide character string type contains UTF-16
 */
#elif SIZEOF_WCHAR_T == 2

/* narrow string conversion functions
 */
#define libbfio_system_string_size_from_narrow_string( narrow_string, narrow_string_size, system_string_size, error ) \
	libuna_utf16_string_size_from_utf8( (libuna_utf8_character_t *) narrow_string, narrow_string_size, system_string_size, error )

#define libbfio_system_string_copy_from_narrow_string( system_string, system_string_size, narrow_string, narrow_string_size, error ) \
	libuna_utf16_string_copy_from_utf8( (libuna_utf16_character_t *) system_string, system_string_size, (libuna_utf8_character_t *) narrow_string, narrow_string_size, error )

#define narrow_string_size_from_libbfio_system_string( system_string, system_string_size, narrow_string_size, error ) \
	libuna_utf8_string_size_from_utf16( (libuna_utf16_character_t *) system_string, system_string_size, narrow_string_size, error )

#define narrow_string_copy_from_libbfio_system_string( narrow_string, narrow_string_size, system_string, system_string_size, error ) \
	libuna_utf8_string_copy_from_utf16( (libuna_utf8_character_t *) narrow_string, narrow_string_size, (libuna_utf16_character_t *) system_string, system_string_size, error )

#else
#error Unsupported size of wchar_t
#endif

/* The system string type contains UTF-8 or ASCII with a codepage
 */
#else

typedef char libbfio_system_character_t;

#define PRIc_LIBBFIO_SYSTEM	"c"
#define PRIs_LIBBFIO_SYSTEM	"s"

#define _LIBBFIO_SYSTEM_STRING( string ) \
	string

#define libbfio_system_string_copy( destination, source, size ) \
	narrow_string_copy( destination, source, size )

#define libbfio_system_string_length( string ) \
	narrow_string_length( string )

#if defined( HAVE_WIDE_CHARACTER_TYPE )

/* The wide character string type contains UTF-32
 */
#if SIZEOF_WCHAR_T == 4

/* wide string conversion functions
 */
#define libbfio_system_string_size_from_wide_string( wide_string, wide_string_size, system_string_size, error ) \
	libuna_utf8_string_size_from_utf32( (libuna_utf32_character_t *) wide_string, wide_string_size, system_string_size, error )

#define libbfio_system_string_copy_from_wide_string( system_string, system_string_size, wide_string, wide_string_size, error ) \
	libuna_utf8_string_copy_from_utf32( (libuna_utf8_character_t *) system_string, system_string_size, (libuna_utf32_character_t *) wide_string, wide_string_size, error )

#define wide_string_size_from_libbfio_system_string( system_string, system_string_size, wide_string_size, error ) \
	libuna_utf32_string_size_from_utf8( (libuna_utf8_character_t *) system_string, system_string_size, wide_string_size, error )

#define wide_string_copy_from_libbfio_system_string( wide_string, wide_string_size, system_string, system_string_size, error ) \
	libuna_utf32_string_copy_from_utf8( (libuna_utf32_character_t *) wide_string, wide_string_size, (libuna_utf8_character_t *) system_string, system_string_size, error )

/* The wide character string type contains UTF-16
 */
#elif SIZEOF_WCHAR_T == 2

/* wide string conversion functions
 */
#define libbfio_system_string_size_from_wide_string( wide_string, wide_string_size, system_string_size, error ) \
	libuna_utf8_string_size_from_utf16( (libuna_utf16_character_t *) wide_string, wide_string_size, system_string_size, error )

#define libbfio_system_string_copy_from_wide_string( system_string, system_string_size, wide_string, wide_string_size, error ) \
	libuna_utf8_string_copy_from_utf16( (libuna_utf8_character_t *) system_string, system_string_size, (libuna_utf16_character_t *) wide_string, wide_string_size, error )

#define wide_string_size_from_libbfio_system_string( system_string, system_string_size, wide_string_size, error ) \
	libuna_utf16_string_size_from_utf8( (libuna_utf8_character_t *) system_string, system_string_size, wide_string_size, error )

#define wide_string_copy_from_libbfio_system_string( wide_string, wide_string_size, system_string, system_string_size, error ) \
	libuna_utf16_string_copy_from_utf8( (libuna_utf16_character_t *) wide_string, wide_string_size, (libuna_utf8_character_t *) system_string, system_string_size, error )

#else
#error Unsupported size of wchar_t
#endif

#endif

#endif

#if defined( _cplusplus )
}
#endif

#endif