Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: ppapi/native_client/src/shared/ppapi_proxy/utility.cc

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include "native_client/src/shared/ppapi_proxy/utility.h"
8
9 #include <stdarg.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "native_client/src/shared/platform/nacl_check.h"
13 #include "native_client/src/include/nacl_assert.h"
14
15 namespace ppapi_proxy {
16
17 const int foo = 5;
18
19 void DebugPrintf(const char* format, ...) {
20 static bool printf_enabled = (getenv("NACL_PPAPI_PROXY_DEBUG") != NULL);
21 if (printf_enabled) {
22 va_list argptr;
23 va_start(argptr, format);
24 #ifdef __native_client__
25 fprintf(stdout, "PPAPI_PROXY_PLUGIN : ");
26 #else
27 fprintf(stdout, "PPAPI_PROXY_BROWSER: ");
28 #endif
29 vfprintf(stdout, format, argptr);
30 va_end(argptr);
31 fflush(stdout);
32 }
33 }
34
35 bool StringIsUtf8(const char* data, uint32_t len) {
36 for (uint32_t i = 0; i < len; i++) {
37 if ((data[i] & 0x80) == 0) {
38 // Single-byte symbol.
39 continue;
40 } else if ((data[i] & 0xc0) == 0x80) {
41 // Invalid first byte.
42 DebugPrintf("Invalid first byte %02x\n", data[i]);
43 return false;
44 }
45 // This is a multi-byte symbol.
46 DebugPrintf("Multi-byte %02x\n", data[i]);
47 // Discard the uppermost bit. The remaining high-order bits are the
48 // unary count of continuation bytes (up to 5 of them).
49 char first = data[i] << 1;
50 uint32_t continuation_bytes = 0;
51 const uint32_t kMaxContinuationBytes = 5;
52 while (first & 0x80) {
53 if (++i >= len) {
54 DebugPrintf("String ended before enough continuation bytes"
55 "were found.\n");
56 return false;
57 } else if (++continuation_bytes > kMaxContinuationBytes) {
58 DebugPrintf("Too many continuation bytes were requested.\n");
59 return false;
60 } else if ((data[i] & 0xc0) != 0x80) {
61 DebugPrintf("Invalid continuation byte.\n");
62 return false;
63 }
64 first <<= 1;
65 }
66 }
67 return true;
68 }
69
70 } // namespace ppapi_proxy
OLDNEW
« no previous file with comments | « ppapi/native_client/src/shared/ppapi_proxy/utility.h ('k') | ppapi/native_client/tests/ppapi/nacl.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698