Blame src/internal/pe_impl.c

feffc7
/*****************************************************************************/
feffc7
/*  pemagination: a (virtual) tour into portable bits and executable bytes   */
feffc7
/*  Copyright (C) 2013,2014,2015  Z. Gilboa                                  */
feffc7
/*  Released under GPLv2 and GPLv3; see COPYING.PEMAGINE.                    */
feffc7
/*****************************************************************************/
feffc7
feffc7
#include <psxtypes/psxtypes.h>
feffc7
#include <pemagine/pemagine.h>
feffc7
#include "pe_impl.h"
feffc7
8860e9
int32_t pe_impl_strlen_ansi(const char * str)
feffc7
{
feffc7
	char * ch;
feffc7
	char * upper_bound;
feffc7
feffc7
	/* sanity check */
feffc7
	upper_bound = (char *)str + PE_STR_MAX_SYMBOL_LEN_ALLOWED;
feffc7
feffc7
	for (ch = (char *)str; (ch < upper_bound) && (*ch); ch++);
feffc7
feffc7
	if (ch < upper_bound)
239ee4
		return (uint32_t)(ch - str);
feffc7
	else
feffc7
		return -1;
feffc7
}
feffc7
feffc7
8860e9
int32_t pe_impl_strlen_utf16(const wchar16_t * str)
feffc7
{
feffc7
	wchar16_t *	wch;
feffc7
	wchar16_t *	upper_bound;
feffc7
feffc7
	/* sanity check */
feffc7
	upper_bound = (wchar16_t *)str + PE_STR_MAX_SYMBOL_LEN_ALLOWED;
feffc7
feffc7
	for (wch = (wchar16_t *)str; (wch < upper_bound) && (*wch); wch++);
feffc7
feffc7
	if (wch < upper_bound)
239ee4
		return (uint32_t)(wch - str);
feffc7
	else
feffc7
		return -1;
feffc7
}
feffc7
feffc7
feffc7
wchar16_t pe_impl_utf16_char_to_lower(const wchar16_t c)
feffc7
{
feffc7
	if ((c >= 'A') && (c <= 'Z'))
feffc7
		return c + 'a' - 'A';
feffc7
	else
feffc7
		return c;
feffc7
}