browser/components/translation/cld2/internal/fixunicodevalue.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Copyright 2013 Google Inc. All Rights Reserved.
     2 //
     3 // Licensed under the Apache License, Version 2.0 (the "License");
     4 // you may not use this file except in compliance with the License.
     5 // You may obtain a copy of the License at
     6 //
     7 //     http://www.apache.org/licenses/LICENSE-2.0
     8 //
     9 // Unless required by applicable law or agreed to in writing, software
    10 // distributed under the License is distributed on an "AS IS" BASIS,
    11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12 // See the License for the specific language governing permissions and
    13 // limitations under the License.
    15 //
    16 // Routine that maps a Unicode code point to an interchange-valid one
    17 //
    19 #include "fixunicodevalue.h"
    20 #include "integral_types.h"
    22 namespace CLD2 {
    24 // Guarantees that the resulting output value is interchange valid
    25 //  00-FF; map to spaces or MS CP1252
    26 //  D800-DFFF; surrogates
    27 //  FDD0-FDEF; non-characters
    28 //  xxFFFE-xxFFFF; non-characters
    29 char32 FixUnicodeValue(char32 uv) {
    30   uint32 uuv = static_cast<uint32>(uv);
    31   if (uuv < 0x0100) {
    32     return kMapFullMicrosoft1252OrSpace[uuv];
    33   }
    34   if (uuv < 0xD800) {
    35     return uv;
    36   }
    37   if ((uuv & ~0x0F) == 0xFDD0) {              // non-characters
    38     return 0xFFFD;
    39   }
    40   if ((uuv & ~0x0F) == 0xFDE0) {              // non-characters
    41     return 0xFFFD;
    42   }
    43   if ((uuv & 0x00FFFE) == 0xFFFE) {           // non-characters
    44     return 0xFFFD;
    45   }
    46   if ((0xE000 <= uuv) && (uuv <= 0x10FFFF))  {
    47     return uv;
    48   }
    49   // surrogates and negative and > 0x10FFFF all land here
    50   return 0xFFFD;
    51 }
    53 }       // End namespace CLD2

mercurial