1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.mojo.bindings;
10 public class BindingsHelper {
12 * Alignment in byte for mojo serialization.
14 public static final int ALIGNMENT = 8;
17 * Align |size| on {@link BindingsHelper#ALIGNMENT}.
19 public static int align(int size) {
20 return (size + ALIGNMENT - 1) & ~(ALIGNMENT - 1);
24 * Compute the size in bytes of the given string encoded as utf8.
26 public static int utf8StringSizeInBytes(String s) {
28 for (int i = 0; i < s.length(); ++i) {
33 char c2 = s.charAt(i);
34 codepoint = Character.toCodePoint(c, c2);
37 if (codepoint > 0x7f) {
39 if (codepoint > 0x7ff) {
41 if (codepoint > 0xffff) {
43 if (codepoint > 0x1fffff) {
45 if (codepoint > 0x3ffffff) {
57 * Determines if the given {@code char} value is a Unicode <i>surrogate code unit</i>. See
58 * {@link Character#isSurrogate}. Extracting here because the method only exists at API level
61 private static boolean isSurrogate(char c) {
62 return c >= Character.MIN_SURROGATE && c < (Character.MAX_SURROGATE + 1);