OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // count number of adjoining spaces | 53 // count number of adjoining spaces |
54 unsigned j = i + 1; | 54 unsigned j = i + 1; |
55 while (j < in.length() && isCollapsibleWhitespace(in[j])) | 55 while (j < in.length() && isCollapsibleWhitespace(in[j])) |
56 j++; | 56 j++; |
57 unsigned count = j - i; | 57 unsigned count = j - i; |
58 consumed = count; | 58 consumed = count; |
59 while (count) { | 59 while (count) { |
60 unsigned add = count % 3; | 60 unsigned add = count % 3; |
61 switch (add) { | 61 switch (add) { |
62 case 0: | 62 case 0: |
63 s.appendLiteral(convertedSpaceString); | 63 s.append(convertedSpaceString); |
64 s.append(' '); | 64 s.append(' '); |
65 s.appendLiteral(convertedSpaceString); | 65 s.append(convertedSpaceString); |
66 add = 3; | 66 add = 3; |
67 break; | 67 break; |
68 case 1: | 68 case 1: |
69 if (i == 0 || i + 1 == in.length()) // at start or end of st
ring | 69 if (i == 0 || i + 1 == in.length()) // at start or end of st
ring |
70 s.appendLiteral(convertedSpaceString); | 70 s.append(convertedSpaceString); |
71 else | 71 else |
72 s.append(' '); | 72 s.append(' '); |
73 break; | 73 break; |
74 case 2: | 74 case 2: |
75 if (i == 0) { | 75 if (i == 0) { |
76 // at start of string | 76 // at start of string |
77 s.appendLiteral(convertedSpaceString); | 77 s.append(convertedSpaceString); |
78 s.append(' '); | 78 s.append(' '); |
79 } else if (i + 2 == in.length()) { | 79 } else if (i + 2 == in.length()) { |
80 // at end of string | 80 // at end of string |
81 s.appendLiteral(convertedSpaceString); | 81 s.append(convertedSpaceString); |
82 s.appendLiteral(convertedSpaceString); | 82 s.append(convertedSpaceString); |
83 } else { | 83 } else { |
84 s.appendLiteral(convertedSpaceString); | 84 s.append(convertedSpaceString); |
85 s.append(' '); | 85 s.append(' '); |
86 } | 86 } |
87 break; | 87 break; |
88 } | 88 } |
89 count -= add; | 89 count -= add; |
90 } | 90 } |
91 } else { | 91 } else { |
92 s.append(in[i]); | 92 s.append(in[i]); |
93 } | 93 } |
94 i += consumed; | 94 i += consumed; |
95 } | 95 } |
96 | 96 |
97 return s.toString(); | 97 return s.toString(); |
98 } | 98 } |
99 | 99 |
100 } // namespace blink | 100 } // namespace blink |
OLD | NEW |