summaryrefslogtreecommitdiffhomepage
path: root/src/internal/pe_impl.c
blob: 3edbe16ddfe5cfcd67acad205d013bc779c7ee83 (plain)
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
/*****************************************************************************/
/*  pemagination: a (virtual) tour into portable bits and executable bytes   */
/*  Copyright (C) 2013,2014,2015  Z. Gilboa                                  */
/*  Released under GPLv2 and GPLv3; see COPYING.PEMAGINE.                    */
/*****************************************************************************/

#include <psxtypes/psxtypes.h>
#include <pemagine/pemagine.h>
#include "pe_impl.h"

int32_t pe_impl_strlen_ansi(const char * str)
{
	const char * ch;
	const char * upper_bound;

	upper_bound = str + PE_STR_MAX_SYMBOL_LEN_ALLOWED;

	for (ch=str; *ch && ch<upper_bound; )
		ch++;

	return (ch < upper_bound)
		? ch - str
		: -1;
}


int32_t pe_impl_strlen_utf16(const wchar16_t * str)
{
	wchar16_t *	wch;
	wchar16_t *	upper_bound;

	/* sanity check */
	upper_bound = (wchar16_t *)str + PE_STR_MAX_SYMBOL_LEN_ALLOWED;

	for (wch = (wchar16_t *)str; (wch < upper_bound) && (*wch); wch++);

	if (wch < upper_bound)
		return ((uint32_t)(wch - str)) * sizeof(wchar16_t);
	else
		return -1;
}


wchar16_t pe_impl_utf16_char_to_lower(const wchar16_t c)
{
	if ((c >= 'A') && (c <= 'Z'))
		return c + 'a' - 'A';
	else
		return c;
}