Improve the UTF-8 handling
This removes some inefficiency, which will be important in these hotspots. Signed-off-by: Gavin Howard <gavin@yzena.com>master
parent
6d4387e9fe
commit
06e112af66
@ -0,0 +1,94 @@
|
||||
/**
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
*
|
||||
* Copyright 2017-2023 Yzena, LLC
|
||||
*
|
||||
* Licensed under the Yzena Viral User License, Version 0.1 (the "Yzena Viral
|
||||
* User License" or "YVUL"), the GNU Affero General Public License (the "GNU
|
||||
* AGPL"), Version 3.0, and the Server Side Public License (the "SSPL"),
|
||||
* Version 1. You may not use this file except in compliance with all of those
|
||||
* licenses.
|
||||
*
|
||||
* You may obtain a copy of the Yzena Viral User License at
|
||||
*
|
||||
* https://yzena.com/yzena-viral-user-license/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the Yzena Viral User License is distributed under the
|
||||
* following disclaimer:
|
||||
*
|
||||
* As far as the law allows, this software comes as is, without any
|
||||
* warranty or condition, and no contributor will be liable to anyone for
|
||||
* any damages related to this software or this license, under any kind of
|
||||
* legal claim.
|
||||
*
|
||||
* You may obtain a copy of the GNU Affero General Public License at
|
||||
*
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the GNU Affero General Public License is distributed under
|
||||
* the following disclaimer:
|
||||
*
|
||||
* 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 Affero
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You may obtain a copy of the Server Side Public License at
|
||||
*
|
||||
* https://www.mongodb.com/licensing/server-side-public-license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the Server Side Public License is distributed under the
|
||||
* following disclaimer:
|
||||
*
|
||||
* 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 Server
|
||||
* Side Public License for more details.
|
||||
*
|
||||
* ****** END LICENSE BLOCK ******
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* ******* BEGIN FILE DESCRIPTION *******
|
||||
*
|
||||
* Code for lexer characters. This is here because the length is stored
|
||||
* specially.
|
||||
*
|
||||
* ******** END FILE DESCRIPTION ********
|
||||
*/
|
||||
|
||||
#include "lang.h"
|
||||
|
||||
#include "../concurrency/strucon.h"
|
||||
#include "../util/utf8.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
y_lang_char_zero(y_lang_Char* c)
|
||||
{
|
||||
y_call_dbg();
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
memset(c, 0, sizeof(y_lang_Char));
|
||||
|
||||
y_return_void_dbg;
|
||||
}
|
||||
|
||||
y_Status
|
||||
y_lang_char_initCodepoint(y_lang_Char* c)
|
||||
{
|
||||
y_Status s;
|
||||
|
||||
y_call_dbg();
|
||||
|
||||
y_assert(c->len >= 1 && c->len <= 4,
|
||||
"Len is not a valid length for a Unicode codepoint");
|
||||
|
||||
s = y_utf8_codepoint_len(c->bytes, c->len, &c->c);
|
||||
|
||||
y_return_dbg(s);
|
||||
}
|
Loading…
Reference in New Issue