OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 { | 44 { |
45 return create(m_value); | 45 return create(m_value); |
46 } | 46 } |
47 | 47 |
48 String SVGNumber::valueAsString() const | 48 String SVGNumber::valueAsString() const |
49 { | 49 { |
50 return String::number(m_value); | 50 return String::number(m_value); |
51 } | 51 } |
52 | 52 |
53 template<typename CharType> | 53 template<typename CharType> |
54 bool SVGNumber::parse(const CharType*& ptr, const CharType* end) | 54 SVGParsingError SVGNumber::parse(const CharType*& ptr, const CharType* end) |
55 { | 55 { |
56 if (!parseNumber(ptr, end, m_value, AllowLeadingAndTrailingWhitespace)) { | 56 float value = 0; |
57 m_value = 0; | 57 const CharType* start = ptr; |
58 return false; | 58 if (!parseNumber(ptr, end, value, AllowLeadingAndTrailingWhitespace)) |
59 } | 59 return SVGParsingError(SVGParseStatus::ExpectedNumber, ptr - start); |
60 | 60 if (ptr != end) |
61 if (ptr != end) { | 61 return SVGParsingError(SVGParseStatus::TrailingGarbage, ptr - start); |
62 m_value = 0; | 62 m_value = value; |
63 return false; | 63 return SVGParseStatus::NoError; |
64 } | |
65 | |
66 return true; | |
67 } | 64 } |
68 | 65 |
69 SVGParsingError SVGNumber::setValueAsString(const String& string) | 66 SVGParsingError SVGNumber::setValueAsString(const String& string) |
70 { | 67 { |
71 if (string.isEmpty()) { | 68 m_value = 0; |
72 m_value = 0; | 69 |
| 70 if (string.isEmpty()) |
73 return SVGParseStatus::NoError; | 71 return SVGParseStatus::NoError; |
74 } | |
75 | 72 |
76 bool valid = false; | |
77 if (string.is8Bit()) { | 73 if (string.is8Bit()) { |
78 const LChar* ptr = string.characters8(); | 74 const LChar* ptr = string.characters8(); |
79 const LChar* end = ptr + string.length(); | 75 const LChar* end = ptr + string.length(); |
80 valid = parse(ptr, end); | 76 return parse(ptr, end); |
81 } else { | |
82 const UChar* ptr = string.characters16(); | |
83 const UChar* end = ptr + string.length(); | |
84 valid = parse(ptr, end); | |
85 } | 77 } |
86 | 78 const UChar* ptr = string.characters16(); |
87 if (!valid) { | 79 const UChar* end = ptr + string.length(); |
88 m_value = 0; | 80 return parse(ptr, end); |
89 return SVGParseStatus::ParsingFailed; | |
90 } | |
91 return SVGParseStatus::NoError; | |
92 } | 81 } |
93 | 82 |
94 void SVGNumber::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement*) | 83 void SVGNumber::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement*) |
95 { | 84 { |
96 setValue(m_value + toSVGNumber(other)->value()); | 85 setValue(m_value + toSVGNumber(other)->value()); |
97 } | 86 } |
98 | 87 |
99 void SVGNumber::calculateAnimatedValue(SVGAnimationElement* animationElement, fl
oat percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> fr
om, PassRefPtrWillBeRawPtr<SVGPropertyBase> to, PassRefPtrWillBeRawPtr<SVGProper
tyBase> toAtEndOfDuration, SVGElement*) | 88 void SVGNumber::calculateAnimatedValue(SVGAnimationElement* animationElement, fl
oat percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> fr
om, PassRefPtrWillBeRawPtr<SVGPropertyBase> to, PassRefPtrWillBeRawPtr<SVGProper
tyBase> toAtEndOfDuration, SVGElement*) |
100 { | 89 { |
101 ASSERT(animationElement); | 90 ASSERT(animationElement); |
(...skipping 23 matching lines...) Expand all Loading... |
125 m_value = 0; | 114 m_value = 0; |
126 return SVGParseStatus::ParsingFailed; | 115 return SVGParseStatus::ParsingFailed; |
127 } | 116 } |
128 | 117 |
129 SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value) | 118 SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value) |
130 : SVGNumber(value) | 119 : SVGNumber(value) |
131 { | 120 { |
132 } | 121 } |
133 | 122 |
134 } | 123 } |
OLD | NEW |