]> git.proxmox.com Git - mirror_ovs.git/blame - lib/unicode.c
Implement JSON parsing and serialization.
[mirror_ovs.git] / lib / unicode.c
CommitLineData
f38b84ea
BP
1/*
2 * Copyright (c) 2009 Nicira Networks.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <config.h>
18
19#include "unicode.h"
20
21/* Returns the unicode code point corresponding to leading surrogate 'leading'
22 * and trailing surrogate 'trailing'. The return value will not make any
23 * sense if 'leading' or 'trailing' are not in the correct ranges for leading
24 * or trailing surrogates. */
25int
26utf16_decode_surrogate_pair(int leading, int trailing)
27{
28 /*
29 * Leading surrogate: 110110wwwwxxxxxx
30 * Trailing surrogate: 110111xxxxxxxxxx
31 * Code point: 000uuuuuxxxxxxxxxxxxxxxx
32 */
33 int w = (leading >> 6) & 0xf;
34 int u = w + 1;
35 int x0 = leading & 0x3f;
36 int x1 = trailing & 0x3ff;
37 return (u << 16) | (x0 << 10) | x1;
38}