forgot to add extra utf8 files

This commit is contained in:
Brad Parker 2016-08-23 19:02:26 -04:00
parent d063cb9283
commit 80d4626908
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,32 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (utf8_util.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_UTF8_UTIL_H__
#define __LIBRETRO_SDK_UTF8_UTIL_H__
#include <stdint.h>
unsigned utf8_strlen(const char *string);
uint8_t utf8_walkbyte(const char **string);
uint32_t utf8_walk(const char **string);
#endif

View File

@ -0,0 +1,39 @@
#include <string/utf8_util.h>
uint32_t utf8_strlen(const char *s)
{
int i = 0, j = 0;
while (s[i]) {
if ((s[i] & 0xc0) != 0x80) j++;
i++;
}
return j;
}
uint8_t utf8_walkbyte(const char **string)
{
return *((*string)++);
}
/* Does not validate the input, returns garbage if it's not UTF-8. */
uint32_t utf8_walk(const char **string)
{
uint8_t first = utf8_walkbyte(string);
uint32_t ret;
if (first<128)
return first;
ret = 0;
ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F);
if (first >= 0xE0)
ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F);
if (first >= 0xF0)
ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F);
if (first >= 0xF0)
return ret | (first&31)<<18;
if (first >= 0xE0)
return ret | (first&15)<<12;
return ret | (first&7)<<6;
}