utf8.c revision a7176505e0083a073d03760f7b5435017a47c7c8
51323288fc628a5cac50914df915545d685b793eLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
51323288fc628a5cac50914df915545d685b793eLennart Poettering This file is part of systemd.
51323288fc628a5cac50914df915545d685b793eLennart Poettering Copyright 2008-2011 Kay Sievers
51323288fc628a5cac50914df915545d685b793eLennart Poettering Copyright 2012 Lennart Poettering
51323288fc628a5cac50914df915545d685b793eLennart Poettering systemd is free software; you can redistribute it and/or modify it
51323288fc628a5cac50914df915545d685b793eLennart Poettering under the terms of the GNU Lesser General Public License as published by
51323288fc628a5cac50914df915545d685b793eLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
51323288fc628a5cac50914df915545d685b793eLennart Poettering (at your option) any later version.
51323288fc628a5cac50914df915545d685b793eLennart Poettering systemd is distributed in the hope that it will be useful, but
51323288fc628a5cac50914df915545d685b793eLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
51323288fc628a5cac50914df915545d685b793eLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
51323288fc628a5cac50914df915545d685b793eLennart Poettering Lesser General Public License for more details.
51323288fc628a5cac50914df915545d685b793eLennart Poettering You should have received a copy of the GNU Lesser General Public License
51323288fc628a5cac50914df915545d685b793eLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
51323288fc628a5cac50914df915545d685b793eLennart Poettering/* Parts of this file are based on the GLIB utf8 validation functions. The
b05f5ae7c5a95f44a59e5d2251879d0ef2af9cb2Lennart Poettering * original license text follows. */
b05f5ae7c5a95f44a59e5d2251879d0ef2af9cb2Lennart Poettering/* gutf8.c - Operations on UTF-8 strings.
b05f5ae7c5a95f44a59e5d2251879d0ef2af9cb2Lennart Poettering * Copyright (C) 1999 Tom Tromey
b05f5ae7c5a95f44a59e5d2251879d0ef2af9cb2Lennart Poettering * Copyright (C) 2000 Red Hat, Inc.
931851e8e492a4d2715e22dcde50a5e7ccef4b49Lennart Poettering * This library is free software; you can redistribute it and/or
51323288fc628a5cac50914df915545d685b793eLennart Poettering * modify it under the terms of the GNU Library General Public
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering * License as published by the Free Software Foundation; either
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering * version 2 of the License, or (at your option) any later version.
#include <errno.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <stdbool.h>
#include "utf8.h"
#include "util.h"
unsigned char c = (unsigned char)str[0];
int unichar;
int len;
switch (len) {
return (int)str[0];
return unichar;
const uint8_t *p;
p += encoded_len;
const uint8_t *p;
if (len < 0)
return NULL;
p += len;
return str;
for (p = str; *p; p++)
return NULL;
return (char*) str;
size_t l;
return NULL;
for (s = str, d = r; *s; s++)
const uint8_t *f;
uint8_t *t;
return NULL;
t = (uint8_t*) r;
uint16_t c;
*(t++) = (uint8_t) c;
int len;
int unichar;
if (len == 0)
for (i = 0; i < len; i++)
return len;