diff options
author | mseaborn@chromium.org <mseaborn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-24 21:06:40 +0000 |
---|---|---|
committer | mseaborn@chromium.org <mseaborn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-24 21:06:40 +0000 |
commit | 0da2ecf6b25b9b18ab3f009e8ba2181b09735b6f (patch) | |
tree | 78f122ce2c66fca31958b737f48058f7a608b36e /ppapi/native_client | |
parent | f92fce5fb9c4e4921bfa8556310ad2530f6ac00f (diff) | |
download | chromium_src-0da2ecf6b25b9b18ab3f009e8ba2181b09735b6f.zip chromium_src-0da2ecf6b25b9b18ab3f009e8ba2181b09735b6f.tar.gz chromium_src-0da2ecf6b25b9b18ab3f009e8ba2181b09735b6f.tar.bz2 |
NaCl: Remove unused file string_encoding.cc
The functions ByteStringAsUTF8() and ByteStringFromUTF8() are no longer used.
BUG=none
TEST=build
Review URL: https://chromiumcodereview.appspot.com/10206009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133765 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/native_client')
6 files changed, 0 insertions, 179 deletions
diff --git a/ppapi/native_client/src/trusted/plugin/build.scons b/ppapi/native_client/src/trusted/plugin/build.scons index 8f6ac35..143c713 100644 --- a/ppapi/native_client/src/trusted/plugin/build.scons +++ b/ppapi/native_client/src/trusted/plugin/build.scons @@ -68,7 +68,6 @@ common_inputs = [ 'service_runtime.cc', 'srpc_client.cc', 'srpc_params.cc', - 'string_encoding.cc', 'utility.cc', ] diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc index 3a66e96..3e1ad2f 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.cc +++ b/ppapi/native_client/src/trusted/plugin/plugin.cc @@ -39,7 +39,6 @@ #include "native_client/src/trusted/plugin/plugin_error.h" #include "native_client/src/trusted/plugin/scriptable_plugin.h" #include "native_client/src/trusted/plugin/service_runtime.h" -#include "native_client/src/trusted/plugin/string_encoding.h" #include "native_client/src/trusted/plugin/utility.h" #include "native_client/src/trusted/service_runtime/nacl_error_code.h" diff --git a/ppapi/native_client/src/trusted/plugin/plugin.gypi b/ppapi/native_client/src/trusted/plugin/plugin.gypi index ef16c2d..c891f28 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.gypi +++ b/ppapi/native_client/src/trusted/plugin/plugin.gypi @@ -18,7 +18,6 @@ 'service_runtime.cc', 'srpc_client.cc', 'srpc_params.cc', - 'string_encoding.cc', 'utility.cc', ], # Append the arch-specific ISA code to common_sources. diff --git a/ppapi/native_client/src/trusted/plugin/string_encoding.cc b/ppapi/native_client/src/trusted/plugin/string_encoding.cc deleted file mode 100644 index 7f3abec..0000000 --- a/ppapi/native_client/src/trusted/plugin/string_encoding.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2011 The Chromium Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "native_client/src/include/nacl_platform.h" -#include "native_client/src/trusted/plugin/string_encoding.h" - - -namespace plugin { - -// PPAPI requires us to encode byte strings as UTF-8. Unfortunately -// this is rather inefficient, in terms of both space and time. - -bool ByteStringAsUTF8(const char* input, size_t input_byte_count, - char** result, size_t* result_byte_count) { - // UTF-8 encoding may result in a 2x size increase at the most. - // TODO(mseaborn): We could do a pre-scan to get the real size. - // If we wanted to be faster, we could do a word-by-word pre-scan - // to check for top-bit-set characters. - size_t max_output_size = input_byte_count * 2; - // We include a null terminator for convenience. - char* output = reinterpret_cast<char*>(malloc(max_output_size + 1)); - if (output == NULL) { - return false; - } - char* dest_ptr = output; - for (size_t i = 0; i < input_byte_count; i++) { - unsigned char ch = input[i]; - if (ch < 128) { - // Code results in a one byte encoding. - *dest_ptr++ = ch; - } else { - // Code results in a two byte encoding. - *dest_ptr++ = 0xc0 | (ch >> 6); /* Top 2 bits */ - *dest_ptr++ = 0x80 | (ch & 0x3f); /* Bottom 6 bits */ - } - } - *dest_ptr = 0; - *result = output; - *result_byte_count = dest_ptr - output; - return true; -} - -bool ByteStringFromUTF8(const char* input, size_t input_byte_count, - char** result, size_t* result_byte_count) { - // The output cannot be larger than the input. - char* output = reinterpret_cast<char*>(malloc(input_byte_count + 1)); - if (output == NULL) { - return NULL; - } - char* dest_ptr = output; - size_t i; - for (i = 0; i < input_byte_count; ) { - unsigned char ch = input[i]; - if ((ch & 0x80) == 0) { - // One byte encoding. - *dest_ptr++ = ch; - i++; - } else { - if (i == input_byte_count - 1) { - // Invalid UTF-8: incomplete sequence. - goto fail; - } - // Check that this is a two byte encoding. - // The first character must contain 110xxxxxb and the - // second must contain 10xxxxxxb. - unsigned char ch2 = input[i + 1]; - if ((ch & 0xe0) != 0xc0) { - // >=2 byte encoding. - goto fail; - } - if ((ch2 & 0xc0) != 0x80) { - // Invalid UTF-8. - goto fail; - } - uint32_t value = (((uint32_t) ch & 0x1f) << 6) | ((uint32_t) ch2 & 0x3f); - if (value < 128) { - // Invalid UTF-8: overly long encoding. - goto fail; - } - if (value >= 0x100) { - // Overly large character. Will not fit into a byte. - goto fail; - } - *dest_ptr++ = value; - i += 2; - } - } - *dest_ptr = 0; - *result = output; - *result_byte_count = dest_ptr - output; - return true; - fail: - free(output); - return false; -} - -} // namespace plugin diff --git a/ppapi/native_client/src/trusted/plugin/string_encoding.h b/ppapi/native_client/src/trusted/plugin/string_encoding.h deleted file mode 100644 index cde7c7c..0000000 --- a/ppapi/native_client/src/trusted/plugin/string_encoding.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2011 The Chromium Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can - * be found in the LICENSE file. - */ - -#ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_STRING_ENCODING_H_ -#define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_STRING_ENCODING_H_ - -#include <stdlib.h> - -namespace plugin { - -bool ByteStringAsUTF8(const char* input, size_t input_byte_count, - char** result, size_t* result_byte_count); -bool ByteStringFromUTF8(const char* input, size_t input_byte_count, - char** result, size_t* result_byte_count); - -} - -#endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_STRING_ENCODING_H_ diff --git a/ppapi/native_client/src/trusted/plugin/string_encoding_test.cc b/ppapi/native_client/src/trusted/plugin/string_encoding_test.cc deleted file mode 100644 index 3e01c67..0000000 --- a/ppapi/native_client/src/trusted/plugin/string_encoding_test.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2010 The Chromium Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can - * be found in the LICENSE file. - */ - -#include <string.h> - -#include "native_client/src/shared/platform/nacl_check.h" -#include "native_client/src/trusted/plugin/string_encoding.h" - - -int main() { - const char* input; - char* output; - size_t output_size; - - // Valid input. - - input = "Hello world, \x80 and \xff"; - CHECK(plugin::ByteStringAsUTF8(input, strlen(input), &output, &output_size)); - CHECK(strcmp(output, "Hello world, \xc2\x80 and \xc3\xbf") == 0); - CHECK(plugin::ByteStringFromUTF8(output, output_size, &output, &output_size)); - CHECK(strcmp(output, "Hello world, \x80 and \xff") == 0); - - // Valid UTF-8, but chars too big. - - // Three-byte sequence - // This encodes \u1000 - input = "\xe1\x80\x80"; - CHECK(!plugin::ByteStringFromUTF8(input, strlen(input), - &output, &output_size)); - // This encodes \u0100 - input = "\xc4\x80"; - CHECK(!plugin::ByteStringFromUTF8(input, strlen(input), - &output, &output_size)); - - // Invalid UTF-8. - - // Incomplete sequence - input = "\xc2"; - CHECK(!plugin::ByteStringFromUTF8(input, strlen(input), - &output, &output_size)); - // Subsequent byte is wrong - input = "\xc2 "; - CHECK(!plugin::ByteStringFromUTF8(input, strlen(input), - &output, &output_size)); - // Over long encoding - // This is a non-canonical encoding for \x00 - input = "\xc0\x80"; - CHECK(!plugin::ByteStringFromUTF8(input, strlen(input), - &output, &output_size)); - - return 0; -} |