~ubuntu-branches/ubuntu/saucy/nodejs/saucy-proposed

« back to all changes in this revision

Viewing changes to deps/v8/src/unicode-inl.h

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#define V8_UNICODE_INL_H_
30
30
 
31
31
#include "unicode.h"
 
32
#include "checks.h"
32
33
 
33
34
namespace unibrow {
34
35
 
78
79
}
79
80
 
80
81
 
81
 
unsigned Utf8::Encode(char* str, uchar c) {
 
82
unsigned Utf8::Encode(char* str, uchar c, int previous) {
82
83
  static const int kMask = ~(1 << 6);
83
84
  if (c <= kMaxOneByteChar) {
84
85
    str[0] = c;
88
89
    str[1] = 0x80 | (c & kMask);
89
90
    return 2;
90
91
  } else if (c <= kMaxThreeByteChar) {
 
92
    if (Utf16::IsTrailSurrogate(c) &&
 
93
        Utf16::IsLeadSurrogate(previous)) {
 
94
      const int kUnmatchedSize = kSizeOfUnmatchedSurrogate;
 
95
      return Encode(str - kUnmatchedSize,
 
96
                    Utf16::CombineSurrogatePair(previous, c),
 
97
                    Utf16::kNoPreviousCharacter) - kUnmatchedSize;
 
98
    }
91
99
    str[0] = 0xE0 | (c >> 12);
92
100
    str[1] = 0x80 | ((c >> 6) & kMask);
93
101
    str[2] = 0x80 | (c & kMask);
113
121
  return CalculateValue(bytes, length, cursor);
114
122
}
115
123
 
116
 
unsigned Utf8::Length(uchar c) {
 
124
unsigned Utf8::Length(uchar c, int previous) {
117
125
  if (c <= kMaxOneByteChar) {
118
126
    return 1;
119
127
  } else if (c <= kMaxTwoByteChar) {
120
128
    return 2;
121
129
  } else if (c <= kMaxThreeByteChar) {
 
130
    if (Utf16::IsTrailSurrogate(c) &&
 
131
        Utf16::IsLeadSurrogate(previous)) {
 
132
      return kSizeOfUnmatchedSurrogate - kBytesSavedByCombiningSurrogates;
 
133
    }
122
134
    return 3;
123
135
  } else {
124
136
    return 4;
133
145
  } else {
134
146
    remaining_--;
135
147
  }
 
148
  ASSERT(BoundsCheck(cursor_));
136
149
  return result;
137
150
}
138
151