Source

cappuccino-docs / cappuccino docs / cappuccino.org / learn / documentation / _c_p_string_8j_source.html

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_string_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:31 GMT -->
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Cappuccino API: Foundation/CPString.j Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>Foundation/CPString.j</h1><a href="_c_p_string_8j.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * CPString.j</span>
<a name="l00003"></a>00003 <span class="comment"> * Foundation</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Created by Francisco Tolmasky.</span>
<a name="l00006"></a>00006 <span class="comment"> * Copyright 2008, 280 North, Inc.</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
<a name="l00009"></a>00009 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
<a name="l00010"></a>00010 <span class="comment"> * License as published by the Free Software Foundation; either</span>
<a name="l00011"></a>00011 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
<a name="l00016"></a>00016 <span class="comment"> * Lesser General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
<a name="l00019"></a>00019 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPObject.j&quot;</span>
<a name="l00024"></a>00024 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPException.j&quot;</span>
<a name="l00025"></a>00025 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPSortDescriptor.j&quot;</span>
<a name="l00026"></a>00026 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPValue.j&quot;</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 
<a name="l00034"></a><a class="code" href="_c_p_string_8j.html#a5b4af16356e82b5c28b04f813636ec16">00034</a> <a class="code" href="_c_p_string_8j.html#a5b4af16356e82b5c28b04f813636ec16">CPCaseInsensitiveSearch</a> = 1;
<a name="l00040"></a><a class="code" href="_c_p_string_8j.html#a6f59c957155f06f46f565fb58bf194d9">00040</a> <a class="code" href="_c_p_string_8j.html#a6f59c957155f06f46f565fb58bf194d9">CPLiteralSearch</a>         = 2;
<a name="l00046"></a><a class="code" href="_c_p_string_8j.html#ab0c2e1bd8c24f5a0afd3322f31f5698a">00046</a> <a class="code" href="_c_p_string_8j.html#ab0c2e1bd8c24f5a0afd3322f31f5698a">CPBackwardsSearch</a>       = 4;
<a name="l00051"></a><a class="code" href="_c_p_string_8j.html#afe6f7ae6745edd20b60589b232baef4e">00051</a> <a class="code" href="_c_p_string_8j.html#afe6f7ae6745edd20b60589b232baef4e">CPAnchoredSearch</a>        = 8;
<a name="l00057"></a><a class="code" href="_c_p_string_8j.html#a85a45340a775ca094ec88be67d82a1cc">00057</a> <a class="code" href="_c_p_string_8j.html#a85a45340a775ca094ec88be67d82a1cc">CPNumericSearch</a>         = 64;
<a name="l00058"></a>00058 
<a name="l00059"></a><a class="code" href="_c_p_string_8j.html#a7624eafcfe935c3e34af3ba787aebce8">00059</a> var <a class="code" href="_c_p_string_8j.html#a7624eafcfe935c3e34af3ba787aebce8">CPStringUIDs</a>        = <span class="keyword">new</span> CFMutableDictionary();
<a name="l00060"></a>00060 
<a name="l00061"></a><a class="code" href="_c_p_string_8j.html#a1a818b8712b35d23aa0fc88cb60cc6ae">00061</a> var <a class="code" href="_c_p_string_8j.html#a1a818b8712b35d23aa0fc88cb60cc6ae">CPStringRegexSpecialCharacters</a> = [
<a name="l00062"></a>00062       <span class="charliteral">&apos;/&apos;</span>, <span class="charliteral">&apos;.&apos;</span>, <span class="charliteral">&apos;*&apos;</span>, <span class="charliteral">&apos;+&apos;</span>, <span class="charliteral">&apos;?&apos;</span>, <span class="charliteral">&apos;|&apos;</span>, <span class="charliteral">&apos;$&apos;</span>, <span class="charliteral">&apos;^&apos;</span>,
<a name="l00063"></a>00063       <span class="charliteral">&apos;(&apos;</span>, <span class="charliteral">&apos;)&apos;</span>, <span class="charliteral">&apos;[&apos;</span>, <span class="charliteral">&apos;]&apos;</span>, <span class="charliteral">&apos;{&apos;</span>, <span class="charliteral">&apos;}&apos;</span>, <span class="charliteral">&apos;\\&apos;</span>
<a name="l00064"></a>00064     ],
<a name="l00065"></a><a class="code" href="_c_p_string_8j.html#a3e01fdc8e6e779c22ce14b54aa2ed88b">00065</a>     <a class="code" href="_c_p_string_8j.html#a3e01fdc8e6e779c22ce14b54aa2ed88b">CPStringRegexEscapeExpression</a> = <span class="keyword">new</span> RegExp(<span class="stringliteral">&quot;(\\&quot;</span> + <a class="code" href="_c_p_string_8j.html#a1a818b8712b35d23aa0fc88cb60cc6ae">CPStringRegexSpecialCharacters</a>.join(<span class="stringliteral">&quot;|\\&quot;</span>) + <span class="stringliteral">&quot;)&quot;</span>, <span class="charliteral">&apos;g&apos;</span>),
<a name="l00066"></a><a class="code" href="_c_p_string_8j.html#a4996fd9879780de49dbbfa0a24ce1d87">00066</a>     <a class="code" href="_c_p_string_8j.html#a4996fd9879780de49dbbfa0a24ce1d87">CPStringRegexTrimWhitespace</a> = <span class="keyword">new</span> RegExp(<span class="stringliteral">&quot;(^\\s+|\\s+$)&quot;</span>, <span class="charliteral">&apos;g&apos;</span>);
<a name="l00067"></a>00067 
<a name="l00081"></a>00081 <span class="keyword">@implementation </span><a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a> : <a class="code" href="class_c_p_object.html" title="The root class from which most classes are subclassed.">CPObject</a>
<a name="l00082"></a>00082 
<a name="l00083"></a>00083 <span class="comment">/*</span>
<a name="l00084"></a>00084 <span class="comment">    @ignore</span>
<a name="l00085"></a>00085 <span class="comment">*/</span>
<a name="l00086"></a>00086 + (id)alloc
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088     <span class="keywordflow">return</span> <span class="keyword">new</span> String;
<a name="l00089"></a>00089 }
<a name="l00090"></a>00090 
<a name="l00094"></a>00094 + (id)<a class="code" href="class_c_p_string.html#a2c829cdee6f107947e586c96b4d7237b">string</a>
<a name="l00095"></a>00095 {
<a name="l00096"></a>00096     <span class="keywordflow">return</span> [[<span class="keyword">self</span> alloc] init];
<a name="l00097"></a>00097 }
<a name="l00098"></a>00098 
<a name="l00103"></a><a class="code" href="class_c_p_string.html#a8cfed134036d37dc7bf80abd9086c57d">00103</a> + (id)stringWithHash:(<span class="keywordtype">unsigned</span>)aHash
<a name="l00104"></a>00104 {
<a name="l00105"></a>00105     var hashString = parseInt(aHash, 10).toString(16);
<a name="l00106"></a>00106     <span class="keywordflow">return</span> <span class="stringliteral">&quot;000000&quot;</span>.substring(0, <a class="code" href="_c_p_obj_j_runtime_8j.html#a45f5f88d061da0c18bcb6b6a854fe898">MAX</a>(6-hashString.length, 0)) + hashString;
<a name="l00107"></a>00107 }
<a name="l00108"></a>00108 
<a name="l00115"></a><a class="code" href="class_c_p_string.html#af25cf8445af121c0a21ae71fcd446ca2">00115</a> + (id)stringWithString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00116"></a>00116 {
<a name="l00117"></a>00117     <span class="keywordflow">if</span> (!aString)
<a name="l00118"></a>00118         [<a class="code" href="class_c_p_exception.html" title="Used to implement exception handling (creating &amp;amp; raising).">CPException</a> <a class="code" href="class_c_p_exception.html#ac8f34bd11868822e26a7b952810128b8">raise</a>:CPInvalidArgumentException
<a name="l00119"></a>00119                     <a class="code" href="class_c_p_exception.html#ac8f34bd11868822e26a7b952810128b8">reason</a>:&quot;stringWithString: the string can&apos;t be &apos;nil&apos;&quot;];
<a name="l00120"></a>00120 
<a name="l00121"></a>00121     <span class="keywordflow">return</span> [[<span class="keyword">self</span> alloc] initWithString:aString];
<a name="l00122"></a>00122 }
<a name="l00123"></a>00123 
<a name="l00129"></a><a class="code" href="class_c_p_string.html#ae45ed35f6c824e8a41de02b7e353b2e1">00129</a> - (id)initWithString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00130"></a>00130 {
<a name="l00131"></a>00131     <span class="keywordflow">return</span> String(aString);
<a name="l00132"></a>00132 }
<a name="l00133"></a>00133 
<a name="l00139"></a><a class="code" href="class_c_p_string.html#af8c14f98424579fac6476bdb79b297c3">00139</a> - (id)initWithFormat:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)format, ...
<a name="l00140"></a>00140 {
<a name="l00141"></a>00141     <span class="keywordflow">if</span> (!format)
<a name="l00142"></a>00142         [<a class="code" href="class_c_p_exception.html" title="Used to implement exception handling (creating &amp;amp; raising).">CPException</a> <a class="code" href="class_c_p_exception.html#ac8f34bd11868822e26a7b952810128b8">raise</a>:CPInvalidArgumentException
<a name="l00143"></a>00143                     <a class="code" href="class_c_p_exception.html#ac8f34bd11868822e26a7b952810128b8">reason</a>:&quot;initWithFormat: the format can&apos;t be &apos;nil&apos;&quot;];
<a name="l00144"></a>00144 
<a name="l00145"></a>00145     <span class="keyword">self</span> = ObjectiveJ.sprintf.apply(<span class="keyword">this</span>, Array.prototype.slice.call(arguments, 2));
<a name="l00146"></a>00146     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00147"></a>00147 }
<a name="l00148"></a>00148 
<a name="l00155"></a><a class="code" href="class_c_p_string.html#a7d9e7b4329b51daf0c3b43d6183d4eec">00155</a> + (id)stringWithFormat:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)format, ...
<a name="l00156"></a>00156 {
<a name="l00157"></a>00157     <span class="keywordflow">if</span> (!format)
<a name="l00158"></a>00158         [<a class="code" href="class_c_p_exception.html" title="Used to implement exception handling (creating &amp;amp; raising).">CPException</a> <a class="code" href="class_c_p_exception.html#ac8f34bd11868822e26a7b952810128b8">raise</a>:CPInvalidArgumentException
<a name="l00159"></a>00159                     <a class="code" href="class_c_p_exception.html#ac8f34bd11868822e26a7b952810128b8">reason</a>:&quot;initWithFormat: the format can&apos;t be &apos;nil&apos;&quot;];
<a name="l00160"></a>00160 
<a name="l00161"></a>00161     <span class="keywordflow">return</span> ObjectiveJ.sprintf.apply(<span class="keyword">this</span>, Array.prototype.slice.call(arguments, 2));
<a name="l00162"></a>00162 }
<a name="l00163"></a>00163 
<a name="l00167"></a><a class="code" href="class_c_p_string.html#ad0a0f060009098921e4ad2655fd82e1b">00167</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#ad0a0f060009098921e4ad2655fd82e1b">description</a>
<a name="l00168"></a>00168 {
<a name="l00169"></a>00169     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00170"></a>00170 }
<a name="l00171"></a>00171 
<a name="l00175"></a><a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">00175</a> - (int)<a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a>
<a name="l00176"></a>00176 {
<a name="l00177"></a>00177     <span class="keywordflow">return</span> <a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a>;
<a name="l00178"></a>00178 }
<a name="l00179"></a>00179 
<a name="l00184"></a><a class="code" href="class_c_p_string.html#a037a62f6bfff0e1c1a32f4cd6bec3b5b">00184</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)characterAtIndex:(<span class="keywordtype">unsigned</span>)anIndex
<a name="l00185"></a>00185 {
<a name="l00186"></a>00186     <span class="keywordflow">return</span> charAt(anIndex);
<a name="l00187"></a>00187 }
<a name="l00188"></a>00188 
<a name="l00189"></a>00189 <span class="comment">// Combining strings</span>
<a name="l00190"></a>00190 
<a name="l00197"></a><a class="code" href="class_c_p_string.html#abe3016a898cad99f29ddc1191d7cf4b1">00197</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)stringByAppendingFormat:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)format, ...
<a name="l00198"></a>00198 {
<a name="l00199"></a>00199     <span class="keywordflow">if</span> (!format)
<a name="l00200"></a>00200         [<a class="code" href="class_c_p_exception.html" title="Used to implement exception handling (creating &amp;amp; raising).">CPException</a> <a class="code" href="class_c_p_exception.html#ac8f34bd11868822e26a7b952810128b8">raise</a>:CPInvalidArgumentException <a class="code" href="class_c_p_exception.html#ac8f34bd11868822e26a7b952810128b8">reason</a>:&quot;initWithFormat: the format can&apos;t be &apos;nil&apos;&quot;];
<a name="l00201"></a>00201 
<a name="l00202"></a>00202     <span class="keywordflow">return</span> <span class="keyword">self</span> + ObjectiveJ.sprintf.apply(<span class="keyword">this</span>, Array.prototype.slice.call(arguments, 2));
<a name="l00203"></a>00203 }
<a name="l00204"></a>00204 
<a name="l00210"></a><a class="code" href="class_c_p_string.html#a9ec14a081f74a6ddd6071dd458487a56">00210</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)stringByAppendingString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00211"></a>00211 {
<a name="l00212"></a>00212     <span class="keywordflow">return</span> <span class="keyword">self</span> + aString;
<a name="l00213"></a>00213 }
<a name="l00214"></a>00214 
<a name="l00227"></a><a class="code" href="class_c_p_string.html#a28101ea252c542e1b49f5fe5305a4c3e">00227</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)stringByPaddingToLength:(<span class="keywordtype">unsigned</span>)aLength withString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString startingAtIndex:(<span class="keywordtype">unsigned</span>)anIndex
<a name="l00228"></a>00228 {
<a name="l00229"></a>00229     <span class="keywordflow">if</span> (<a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a> == aLength)
<a name="l00230"></a>00230         <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00231"></a>00231 
<a name="l00232"></a>00232     <span class="keywordflow">if</span> (aLength &lt; <a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a>)
<a name="l00233"></a>00233         <span class="keywordflow">return</span> substr(0, aLength);
<a name="l00234"></a>00234 
<a name="l00235"></a>00235     var <span class="keywordtype">string</span> = <span class="keyword">self</span>,
<a name="l00236"></a>00236         substring = aString.substring(anIndex),
<a name="l00237"></a>00237         difference = aLength - <a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a>;
<a name="l00238"></a>00238 
<a name="l00239"></a>00239     <span class="keywordflow">while</span> ((difference -= substring.length) &gt;= 0)
<a name="l00240"></a>00240         <span class="keywordtype">string</span> += substring;
<a name="l00241"></a>00241     
<a name="l00242"></a>00242     <span class="keywordflow">if</span> (-difference &lt; substring.length) 
<a name="l00243"></a>00243         <span class="keywordtype">string</span> += substring.substring(0, -difference);
<a name="l00244"></a>00244 
<a name="l00245"></a>00245     <span class="keywordflow">return</span> <a class="code" href="class_c_p_string.html#a2c829cdee6f107947e586c96b4d7237b">string</a>;
<a name="l00246"></a>00246 }
<a name="l00247"></a>00247 
<a name="l00248"></a>00248 <span class="comment">//Dividing Strings</span>
<a name="l00260"></a><a class="code" href="class_c_p_string.html#af8568e12727d8d5d33b25f5b1e976e62">00260</a> <span class="comment"></span>- (<a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a>)componentsSeparatedByString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00261"></a>00261 {
<a name="l00262"></a>00262     <span class="keywordflow">return</span> split(aString);
<a name="l00263"></a>00263 }
<a name="l00264"></a>00264 
<a name="l00270"></a><a class="code" href="class_c_p_string.html#a8fb915fde11a018fc9ebaa10af9444e5">00270</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)substringFromIndex:(<span class="keywordtype">unsigned</span>)anIndex
<a name="l00271"></a>00271 {
<a name="l00272"></a>00272     <span class="keywordflow">return</span> substr(anIndex);
<a name="l00273"></a>00273 }
<a name="l00274"></a>00274 
<a name="l00280"></a><a class="code" href="class_c_p_string.html#a0ee023c22aa1e8a6c20fff9fe574dd08">00280</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)substringWithRange:(CPRange)aRange
<a name="l00281"></a>00281 {
<a name="l00282"></a>00282     <span class="keywordflow">return</span> substr(aRange.location, aRange.length);
<a name="l00283"></a>00283 }
<a name="l00284"></a>00284 
<a name="l00290"></a><a class="code" href="class_c_p_string.html#ab74d7a1f416b2299384df2f65d307b27">00290</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)substringToIndex:(<span class="keywordtype">unsigned</span>)anIndex
<a name="l00291"></a>00291 {
<a name="l00292"></a>00292     <span class="keywordflow">return</span> substring(0, anIndex);
<a name="l00293"></a>00293 }
<a name="l00294"></a>00294 
<a name="l00295"></a>00295 <span class="comment">// Finding characters and substrings</span>
<a name="l00296"></a>00296 
<a name="l00303"></a><a class="code" href="class_c_p_string.html#a2f8b1e6c0c44ee0e3a944c8fc03fdde4">00303</a> - (CPRange)rangeOfString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00304"></a>00304 {
<a name="l00305"></a>00305    <span class="keywordflow">return</span> [<span class="keyword">self</span> <a class="code" href="class_c_p_string.html#ac5eb33bdd16fabef7a5f64e6004d565a">rangeOfString</a>:aString <a class="code" href="class_c_p_string.html#ac5eb33bdd16fabef7a5f64e6004d565a">options</a>:0];
<a name="l00306"></a>00306 }
<a name="l00307"></a>00307 
<a name="l00325"></a><a class="code" href="class_c_p_string.html#ac5eb33bdd16fabef7a5f64e6004d565a">00325</a> - (CPRange)rangeOfString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString options:(<span class="keywordtype">int</span>)aMask
<a name="l00326"></a>00326 {
<a name="l00327"></a>00327     <span class="keywordflow">return</span> [<span class="keyword">self</span> <a class="code" href="class_c_p_string.html#a9bc7bb81df0e2d850e0b01e37e81bee7">rangeOfString</a>:aString <a class="code" href="class_c_p_string.html#a9bc7bb81df0e2d850e0b01e37e81bee7">options</a>:aMask <a class="code" href="class_c_p_string.html#a9bc7bb81df0e2d850e0b01e37e81bee7">range</a>:nil];
<a name="l00328"></a>00328 }
<a name="l00329"></a>00329 
<a name="l00348"></a><a class="code" href="class_c_p_string.html#a9bc7bb81df0e2d850e0b01e37e81bee7">00348</a> - (CPRange)rangeOfString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString options:(<span class="keywordtype">int</span>)aMask range:(CPrange)aRange
<a name="l00349"></a>00349 {
<a name="l00350"></a>00350     var <span class="keywordtype">string</span> = (aRange == nil) ? <span class="keyword">self</span> : [<span class="keyword">self</span> substringWithRange:aRange],
<a name="l00351"></a>00351         location = <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a>;
<a name="l00352"></a>00352 
<a name="l00353"></a>00353     <span class="keywordflow">if</span> (aMask &amp; <a class="code" href="_c_p_string_8j.html#a5b4af16356e82b5c28b04f813636ec16">CPCaseInsensitiveSearch</a>)
<a name="l00354"></a>00354     {
<a name="l00355"></a>00355         <span class="keywordtype">string</span> = <span class="keywordtype">string</span>.toLowerCase();
<a name="l00356"></a>00356         aString = aString.toLowerCase();
<a name="l00357"></a>00357     }
<a name="l00358"></a>00358 
<a name="l00359"></a>00359     <span class="keywordflow">if</span> (aMask &amp; <a class="code" href="_c_p_string_8j.html#ab0c2e1bd8c24f5a0afd3322f31f5698a">CPBackwardsSearch</a>)
<a name="l00360"></a>00360         location = <span class="keywordtype">string</span>.lastIndexOf(aString, aMask &amp; <a class="code" href="_c_p_string_8j.html#afe6f7ae6745edd20b60589b232baef4e">CPAnchoredSearch</a> ? <a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a> - aString.<a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a> : 0);
<a name="l00361"></a>00361     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (aMask &amp; <a class="code" href="_c_p_string_8j.html#afe6f7ae6745edd20b60589b232baef4e">CPAnchoredSearch</a>)
<a name="l00362"></a>00362         location = <span class="keywordtype">string</span>.substr(0, aString.<a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a>).indexOf(aString) != <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a> ? 0 : <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a>;
<a name="l00363"></a>00363     <span class="keywordflow">else</span>
<a name="l00364"></a>00364         location = <span class="keywordtype">string</span>.indexOf(aString);
<a name="l00365"></a>00365 
<a name="l00366"></a>00366     <span class="keywordflow">return</span> <a class="code" href="group__foundation.html#ga377fec0972facd19d72b8abcffcdb362">CPMakeRange</a>(location, location == <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a> ? 0 : aString.<a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a>);
<a name="l00367"></a>00367 }
<a name="l00368"></a>00368 
<a name="l00369"></a>00369 <span class="comment">//Replacing Substrings</span>
<a name="l00370"></a>00370 
<a name="l00371"></a><a class="code" href="class_c_p_string.html#a7dda8d94b040e47c7158ab531ca9ac52">00371</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#a7dda8d94b040e47c7158ab531ca9ac52">stringByEscapingRegexControlCharacters</a>
<a name="l00372"></a>00372 {
<a name="l00373"></a>00373     <span class="keywordflow">return</span> <span class="keyword">self</span>.replace(<a class="code" href="_c_p_string_8j.html#a3e01fdc8e6e779c22ce14b54aa2ed88b">CPStringRegexEscapeExpression</a>, <span class="stringliteral">&quot;\\$1&quot;</span>);
<a name="l00374"></a>00374 }
<a name="l00375"></a>00375 
<a name="l00383"></a><a class="code" href="class_c_p_string.html#a907808718ef6814f54579544b6f67a5d">00383</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)stringByReplacingOccurrencesOfString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)target withString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)replacement
<a name="l00384"></a>00384 {
<a name="l00385"></a>00385     <span class="keywordflow">return</span> <span class="keyword">self</span>.replace(<span class="keyword">new</span> RegExp([target <a class="code" href="class_c_p_string.html#a7dda8d94b040e47c7158ab531ca9ac52">stringByEscapingRegexControlCharacters</a>], <span class="stringliteral">&quot;g&quot;</span>), replacement);
<a name="l00386"></a>00386 }
<a name="l00387"></a>00387 
<a name="l00388"></a>00388 <span class="comment">/*</span>
<a name="l00389"></a>00389 <span class="comment">    Returns a new string in which all occurrences of a target string in a specified range of the receiver</span>
<a name="l00390"></a>00390 <span class="comment">    are replaced by another given string.</span>
<a name="l00391"></a>00391 <span class="comment">    @param target The string to replace</span>
<a name="l00392"></a>00392 <span class="comment">    @param replacement the string with which to replace the \c target.</span>
<a name="l00393"></a>00393 <span class="comment">    @param options A mask of options to use when comparing \c target with the receiver. Pass 0 to specify no options</span>
<a name="l00394"></a>00394 <span class="comment">    @param searchRange The range in the receiver in which to search for \c target.</span>
<a name="l00395"></a>00395 <span class="comment">*/</span>
<a name="l00396"></a>00396 
<a name="l00397"></a><a class="code" href="class_c_p_string.html#a56e9ec6d7d6556f19a5bb94e71f253a1">00397</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)stringByReplacingOccurrencesOfString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)target withString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)replacement options:(<span class="keywordtype">int</span>)options range:(CPRange)searchRange
<a name="l00398"></a>00398 {
<a name="l00399"></a>00399     var start = substring(0, searchRange.location),
<a name="l00400"></a>00400         stringSegmentToSearch = substr(searchRange.location, searchRange.length),
<a name="l00401"></a>00401         end = substring(searchRange.location + searchRange.length, <span class="keyword">self</span>.length),
<a name="l00402"></a>00402         target = [target <a class="code" href="class_c_p_string.html#a7dda8d94b040e47c7158ab531ca9ac52">stringByEscapingRegexControlCharacters</a>],
<a name="l00403"></a>00403         regExp;
<a name="l00404"></a>00404 
<a name="l00405"></a>00405     <span class="keywordflow">if</span> (options &amp; <a class="code" href="_c_p_string_8j.html#a5b4af16356e82b5c28b04f813636ec16">CPCaseInsensitiveSearch</a>)
<a name="l00406"></a>00406         regExp = <span class="keyword">new</span> RegExp(target, <span class="stringliteral">&quot;gi&quot;</span>); 
<a name="l00407"></a>00407     <span class="keywordflow">else</span>
<a name="l00408"></a>00408         regExp = <span class="keyword">new</span> RegExp(target, <span class="stringliteral">&quot;g&quot;</span>);
<a name="l00409"></a>00409 
<a name="l00410"></a>00410     <span class="keywordflow">return</span> start + <span class="stringliteral">&apos;&apos;</span> + stringSegmentToSearch.replace(regExp, replacement) + <span class="stringliteral">&apos;&apos;</span> + end;
<a name="l00411"></a>00411 }
<a name="l00412"></a>00412 
<a name="l00413"></a>00413 <span class="comment">/*</span>
<a name="l00414"></a>00414 <span class="comment">   Returns a new string in which the characters in a specified range of the receiver </span>
<a name="l00415"></a>00415 <span class="comment">   are replaced by a given string.</span>
<a name="l00416"></a>00416 <span class="comment">   @param range A range of characters in the receiver.</span>
<a name="l00417"></a>00417 <span class="comment">   @param replacement The string with which to replace the characters in \c range.</span>
<a name="l00418"></a>00418 <span class="comment">*/</span>
<a name="l00419"></a>00419 
<a name="l00420"></a><a class="code" href="class_c_p_string.html#a7da453cc160237a3a42c90a478ac244f">00420</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)stringByReplacingCharactersInRange:(CPRange)range withString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)replacement
<a name="l00421"></a>00421 {
<a name="l00422"></a>00422         <span class="keywordflow">return</span> <span class="stringliteral">&apos;&apos;</span> + substring(0, range.location) + replacement + substring(range.location + range.length, <span class="keyword">self</span>.length);
<a name="l00423"></a>00423 }
<a name="l00424"></a>00424 
<a name="l00428"></a><a class="code" href="class_c_p_string.html#acc43c53f71bcaf5d5e19ec9af3590dc3">00428</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#acc43c53f71bcaf5d5e19ec9af3590dc3">stringByTrimmingWhitespace</a>
<a name="l00429"></a>00429 {
<a name="l00430"></a>00430     <span class="keywordflow">return</span> <span class="keyword">self</span>.replace(<a class="code" href="_c_p_string_8j.html#a4996fd9879780de49dbbfa0a24ce1d87">CPStringRegexTrimWhitespace</a>, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00431"></a>00431 }
<a name="l00432"></a>00432 
<a name="l00433"></a>00433 <span class="comment">// Identifying and comparing strings</span>
<a name="l00434"></a>00434 
<a name="l00440"></a><a class="code" href="class_c_p_string.html#a4a30ec63a63398253593feed51b24c9e">00440</a> - (CPComparisonResult)compare:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00441"></a>00441 {
<a name="l00442"></a>00442     <span class="keywordflow">return</span> [<span class="keyword">self</span> <a class="code" href="class_c_p_string.html#a59c8466310d73bfd30311b4e8fe709b7">compare</a>:aString <a class="code" href="class_c_p_string.html#a59c8466310d73bfd30311b4e8fe709b7">options</a>:nil];
<a name="l00443"></a>00443 }
<a name="l00444"></a>00444 
<a name="l00445"></a>00445 
<a name="l00446"></a>00446 <span class="comment">/*</span>
<a name="l00447"></a>00447 <span class="comment">    Compares the receiver to the specified string.</span>
<a name="l00448"></a>00448 <span class="comment">    @param aString the string with which to compare</span>
<a name="l00449"></a>00449 <span class="comment">    @return the result of the comparison</span>
<a name="l00450"></a>00450 <span class="comment">*/</span>
<a name="l00451"></a><a class="code" href="class_c_p_string.html#a28c9bc46aa22ba1a284762e2c6d9ff01">00451</a> - (CPComparisonResult)caseInsensitiveCompare:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00452"></a>00452 {
<a name="l00453"></a>00453     <span class="keywordflow">return</span> [<span class="keyword">self</span> <a class="code" href="class_c_p_string.html#a59c8466310d73bfd30311b4e8fe709b7">compare</a>:aString <a class="code" href="class_c_p_string.html#a59c8466310d73bfd30311b4e8fe709b7">options</a>:CPCaseInsensitiveSearch];
<a name="l00454"></a>00454 }
<a name="l00455"></a>00455 
<a name="l00462"></a><a class="code" href="class_c_p_string.html#a59c8466310d73bfd30311b4e8fe709b7">00462</a> - (CPComparisonResult)compare:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString options:(<span class="keywordtype">int</span>)aMask
<a name="l00463"></a>00463 {
<a name="l00464"></a>00464     var lhs = <span class="keyword">self</span>,
<a name="l00465"></a>00465         rhs = aString;
<a name="l00466"></a>00466     
<a name="l00467"></a>00467     <span class="keywordflow">if</span> (aMask &amp; <a class="code" href="_c_p_string_8j.html#a5b4af16356e82b5c28b04f813636ec16">CPCaseInsensitiveSearch</a>)
<a name="l00468"></a>00468     {
<a name="l00469"></a>00469         lhs = lhs.toLowerCase();
<a name="l00470"></a>00470         rhs = rhs.toLowerCase();
<a name="l00471"></a>00471     }
<a name="l00472"></a>00472     
<a name="l00473"></a>00473     <span class="keywordflow">if</span> (lhs &lt; rhs)
<a name="l00474"></a>00474         <span class="keywordflow">return</span> <a class="code" href="_c_p_obj_j_runtime_8j.html#a3e9b85c1be28d3092262626ffcf41993">CPOrderedAscending</a>;
<a name="l00475"></a>00475     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (lhs &gt; rhs)
<a name="l00476"></a>00476         <span class="keywordflow">return</span> <a class="code" href="_c_p_obj_j_runtime_8j.html#aad9efd5d7748d296944239adb552f67c">CPOrderedDescending</a>;
<a name="l00477"></a>00477     
<a name="l00478"></a>00478     <span class="keywordflow">return</span> <a class="code" href="_c_p_obj_j_runtime_8j.html#af6563f83ad093188bcbdba78aa1848c5">CPOrderedSame</a>;
<a name="l00479"></a>00479 }
<a name="l00480"></a>00480 
<a name="l00488"></a><a class="code" href="class_c_p_string.html#af941d3948ba4bf0949ae7ac2399de87a">00488</a> - (CPComparisonResult)compare:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString options:(<span class="keywordtype">int</span>)aMask range:(CPRange)range
<a name="l00489"></a>00489 {
<a name="l00490"></a>00490     var lhs = [<span class="keyword">self</span> <a class="code" href="class_c_p_string.html#a0ee023c22aa1e8a6c20fff9fe574dd08">substringWithRange</a>:range],
<a name="l00491"></a>00491         rhs = aString;
<a name="l00492"></a>00492 
<a name="l00493"></a>00493     <span class="keywordflow">return</span> [lhs compare:rhs options:aMask];
<a name="l00494"></a>00494 }
<a name="l00495"></a>00495 
<a name="l00501"></a><a class="code" href="class_c_p_string.html#a99ca267397f8dac29beed6973a525706">00501</a> - (BOOL)hasPrefix:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00502"></a>00502 {
<a name="l00503"></a>00503     <span class="keywordflow">return</span> aString &amp;&amp; aString != <span class="stringliteral">&quot;&quot;</span> &amp;&amp; indexOf(aString) == 0;
<a name="l00504"></a>00504 }
<a name="l00505"></a>00505 
<a name="l00511"></a><a class="code" href="class_c_p_string.html#a3c488d47533880d4aa113e5a4a5d6ed8">00511</a> - (BOOL)hasSuffix:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00512"></a>00512 {
<a name="l00513"></a>00513     <span class="keywordflow">return</span> aString &amp;&amp; aString != <span class="stringliteral">&quot;&quot;</span> &amp;&amp; <a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a> &gt;= aString.<a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a> &amp;&amp; lastIndexOf(aString) == (<a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a> - aString.<a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a>);
<a name="l00514"></a>00514 }
<a name="l00515"></a>00515 
<a name="l00519"></a><a class="code" href="class_c_p_string.html#ae0aa9d104f6cd6336095094e2a7c8441">00519</a> - (BOOL)isEqualToString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00520"></a>00520 {
<a name="l00521"></a>00521     <span class="keywordflow">return</span> <span class="keyword">self</span> == aString;
<a name="l00522"></a>00522 }
<a name="l00523"></a>00523 
<a name="l00527"></a><a class="code" href="class_c_p_string.html#a3c8d8fc3c4e0fe4656812709c098943b">00527</a> - (unsigned)<a class="code" href="class_c_p_string.html#a3c8d8fc3c4e0fe4656812709c098943b">UID</a>
<a name="l00528"></a>00528 {
<a name="l00529"></a>00529     var <a class="code" href="class_c_p_string.html#a3c8d8fc3c4e0fe4656812709c098943b">UID</a> = <a class="code" href="_c_p_string_8j.html#a7624eafcfe935c3e34af3ba787aebce8">CPStringUIDs</a>.valueForKey(<span class="keyword">self</span>);
<a name="l00530"></a>00530 
<a name="l00531"></a>00531     <span class="keywordflow">if</span> (!<a class="code" href="class_c_p_string.html#a3c8d8fc3c4e0fe4656812709c098943b">UID</a>)
<a name="l00532"></a>00532     {
<a name="l00533"></a>00533         <a class="code" href="class_c_p_string.html#a3c8d8fc3c4e0fe4656812709c098943b">UID</a> = objj_generateObjectUID();
<a name="l00534"></a>00534         <a class="code" href="_c_p_string_8j.html#a7624eafcfe935c3e34af3ba787aebce8">CPStringUIDs</a>.setValueForKey(<span class="keyword">self</span>, <a class="code" href="class_c_p_string.html#a3c8d8fc3c4e0fe4656812709c098943b">UID</a>);
<a name="l00535"></a>00535     }
<a name="l00536"></a>00536 
<a name="l00537"></a>00537     <span class="keywordflow">return</span> <a class="code" href="class_c_p_string.html#a3c8d8fc3c4e0fe4656812709c098943b">UID</a> + <span class="stringliteral">&quot;&quot;</span>;
<a name="l00538"></a>00538 }
<a name="l00539"></a>00539 
<a name="l00545"></a><a class="code" href="class_c_p_string.html#a4cd6dedc1cf59dd58a712015a1ff6657">00545</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)commonPrefixWithString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00546"></a>00546 {
<a name="l00547"></a>00547     <span class="keywordflow">return</span> [<span class="keyword">self</span> <a class="code" href="class_c_p_string.html#a2eb2cdb6ae5a9cec2d04a4b2c6356b75">commonPrefixWithString</a>: aString <a class="code" href="class_c_p_string.html#a2eb2cdb6ae5a9cec2d04a4b2c6356b75">options</a>: 0];
<a name="l00548"></a>00548 }
<a name="l00549"></a>00549 
<a name="l00556"></a><a class="code" href="class_c_p_string.html#a2eb2cdb6ae5a9cec2d04a4b2c6356b75">00556</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)commonPrefixWithString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString options:(<span class="keywordtype">int</span>)aMask
<a name="l00557"></a>00557 {
<a name="l00558"></a>00558     var len = 0, <span class="comment">// length of common prefix</span>
<a name="l00559"></a>00559         lhs = <span class="keyword">self</span>,
<a name="l00560"></a>00560         rhs = aString,
<a name="l00561"></a>00561         min = <a class="code" href="_c_p_obj_j_runtime_8j.html#a4fca277171215842609dc38a6f0c19fb">MIN</a>([lhs <a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a>], [rhs <a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a>]);
<a name="l00562"></a>00562     
<a name="l00563"></a>00563     <span class="keywordflow">if</span> (aMask &amp; <a class="code" href="_c_p_string_8j.html#a5b4af16356e82b5c28b04f813636ec16">CPCaseInsensitiveSearch</a>)
<a name="l00564"></a>00564     {
<a name="l00565"></a>00565         lhs = [lhs lowercaseString];
<a name="l00566"></a>00566         rhs = [rhs lowercaseString];
<a name="l00567"></a>00567     }
<a name="l00568"></a>00568 
<a name="l00569"></a>00569     <span class="keywordflow">for</span> (; len &lt; min; len++ )
<a name="l00570"></a>00570     {
<a name="l00571"></a>00571         <span class="keywordflow">if</span> ( [lhs characterAtIndex:len] !== [rhs characterAtIndex:len] )
<a name="l00572"></a>00572             <span class="keywordflow">break</span>;
<a name="l00573"></a>00573     }
<a name="l00574"></a>00574 
<a name="l00575"></a>00575     <span class="keywordflow">return</span> [<span class="keyword">self</span> <a class="code" href="class_c_p_string.html#ab74d7a1f416b2299384df2f65d307b27">substringToIndex</a>:len];
<a name="l00576"></a>00576 }
<a name="l00577"></a>00577 
<a name="l00581"></a><a class="code" href="class_c_p_string.html#a1f07c3c7c5741875ca92ff7f35aa7da4">00581</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#a1f07c3c7c5741875ca92ff7f35aa7da4">capitalizedString</a>
<a name="l00582"></a>00582 {
<a name="l00583"></a>00583     var parts = <span class="keyword">self</span>.split(/\b/g); <span class="comment">// split on word boundaries</span>
<a name="l00584"></a>00584     <span class="keywordflow">for</span> (var i = 0; i &lt; parts.length; i++)
<a name="l00585"></a>00585     {
<a name="l00586"></a>00586         <span class="keywordflow">if</span> (i == 0 || (/\s$/).test(parts[i-1])) <span class="comment">// only capitalize if previous token was whitespace</span>
<a name="l00587"></a>00587             parts[i] = parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1).toLowerCase();
<a name="l00588"></a>00588         <span class="keywordflow">else</span>
<a name="l00589"></a>00589             parts[i] = parts[i].toLowerCase();
<a name="l00590"></a>00590     }
<a name="l00591"></a>00591     <span class="keywordflow">return</span> parts.join(<span class="stringliteral">&quot;&quot;</span>);
<a name="l00592"></a>00592 }
<a name="l00593"></a>00593 
<a name="l00597"></a><a class="code" href="class_c_p_string.html#ac403c7e2ff478252271e581b6ab8f1a4">00597</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#ac403c7e2ff478252271e581b6ab8f1a4">lowercaseString</a>
<a name="l00598"></a>00598 {
<a name="l00599"></a>00599     <span class="keywordflow">return</span> toLowerCase();
<a name="l00600"></a>00600 }
<a name="l00601"></a>00601 
<a name="l00605"></a><a class="code" href="class_c_p_string.html#a3283fbcf240b4fa46524db8cf20145f4">00605</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#a3283fbcf240b4fa46524db8cf20145f4">uppercaseString</a>
<a name="l00606"></a>00606 {
<a name="l00607"></a>00607     <span class="keywordflow">return</span> toUpperCase();
<a name="l00608"></a>00608 }
<a name="l00609"></a>00609 
<a name="l00613"></a><a class="code" href="class_c_p_string.html#a16c05c776a5eaaaf8729a9b37c606bba">00613</a> - (double)<a class="code" href="class_c_p_string.html#a16c05c776a5eaaaf8729a9b37c606bba">doubleValue</a>
<a name="l00614"></a>00614 {
<a name="l00615"></a>00615     <span class="keywordflow">return</span> parseFloat(<span class="keyword">self</span>, 10);
<a name="l00616"></a>00616 }
<a name="l00623"></a><a class="code" href="class_c_p_string.html#ad28c2121d6cd50e9f9774cd8dd545c1e">00623</a> - (BOOL)<a class="code" href="class_c_p_string.html#ad28c2121d6cd50e9f9774cd8dd545c1e">boolValue</a>
<a name="l00624"></a>00624 {
<a name="l00625"></a>00625     var replaceRegExp = <span class="keyword">new</span> RegExp(<span class="stringliteral">&quot;^\\s*[\\+,\\-]*0*&quot;</span>);
<a name="l00626"></a>00626     <span class="keywordflow">return</span> RegExp(<span class="stringliteral">&quot;^[Y,y,t,T,1-9]&quot;</span>).test(<span class="keyword">self</span>.replace(replaceRegExp, <span class="stringliteral">&apos;&apos;</span>));
<a name="l00627"></a>00627 }
<a name="l00628"></a>00628 
<a name="l00632"></a><a class="code" href="class_c_p_string.html#a6567781f2eea563dbe0bdc77a00c4d6f">00632</a> - (float)<a class="code" href="class_c_p_string.html#a6567781f2eea563dbe0bdc77a00c4d6f">floatValue</a>
<a name="l00633"></a>00633 {
<a name="l00634"></a>00634     <span class="keywordflow">return</span> parseFloat(<span class="keyword">self</span>, 10);
<a name="l00635"></a>00635 }
<a name="l00636"></a>00636 
<a name="l00640"></a><a class="code" href="class_c_p_string.html#aeab6515f1cbdf9cac64463c3ee30c465">00640</a> - (int)<a class="code" href="class_c_p_string.html#aeab6515f1cbdf9cac64463c3ee30c465">intValue</a>
<a name="l00641"></a>00641 {
<a name="l00642"></a>00642     <span class="keywordflow">return</span> parseInt(<span class="keyword">self</span>, 10);
<a name="l00643"></a>00643 }
<a name="l00644"></a>00644 
<a name="l00650"></a><a class="code" href="class_c_p_string.html#a7b7a8c7623f08e6678bb49aab89abc2f">00650</a> - (<a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a>)<a class="code" href="class_c_p_string.html#a7b7a8c7623f08e6678bb49aab89abc2f">pathComponents</a>
<a name="l00651"></a>00651 {
<a name="l00652"></a>00652     var result = split(<span class="charliteral">&apos;/&apos;</span>);
<a name="l00653"></a>00653     <span class="keywordflow">if</span> (result[0] === <span class="stringliteral">&quot;&quot;</span>)
<a name="l00654"></a>00654         result[0] = <span class="stringliteral">&quot;/&quot;</span>;
<a name="l00655"></a>00655     <span class="keywordflow">if</span> (result[result.length - 1] === <span class="stringliteral">&quot;&quot;</span>)
<a name="l00656"></a>00656         result.pop();
<a name="l00657"></a>00657     <span class="keywordflow">return</span> result;
<a name="l00658"></a>00658 }
<a name="l00659"></a>00659 
<a name="l00665"></a><a class="code" href="class_c_p_string.html#a7e33159121dd01afad290dca481dc06f">00665</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#a7e33159121dd01afad290dca481dc06f">pathExtension</a>
<a name="l00666"></a>00666 {
<a name="l00667"></a>00667     <span class="keywordflow">return</span> substr(lastIndexOf(<span class="charliteral">&apos;.&apos;</span>) + 1);
<a name="l00668"></a>00668 }
<a name="l00669"></a>00669 
<a name="l00675"></a><a class="code" href="class_c_p_string.html#ae3defdd5560a6206b6fc975194fb5fc6">00675</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#ae3defdd5560a6206b6fc975194fb5fc6">lastPathComponent</a>
<a name="l00676"></a>00676 {
<a name="l00677"></a>00677     var components = [<span class="keyword">self</span> <a class="code" href="class_c_p_string.html#a7b7a8c7623f08e6678bb49aab89abc2f">pathComponents</a>];
<a name="l00678"></a>00678     <span class="keywordflow">return</span> components[components.length -1];
<a name="l00679"></a>00679 }
<a name="l00680"></a>00680 
<a name="l00686"></a><a class="code" href="class_c_p_string.html#a0902226e8c4d553712d67f0fec0feb53">00686</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#a0902226e8c4d553712d67f0fec0feb53">stringByDeletingLastPathComponent</a>
<a name="l00687"></a>00687 {
<a name="l00688"></a>00688     var path = <span class="keyword">self</span>,
<a name="l00689"></a>00689         start = <a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a> - 1;
<a name="l00690"></a>00690     
<a name="l00691"></a>00691     <span class="keywordflow">while</span> (path.charAt(start) === <span class="charliteral">&apos;/&apos;</span>)
<a name="l00692"></a>00692         start--;
<a name="l00693"></a>00693     
<a name="l00694"></a>00694     path = path.substr(0, path.lastIndexOf(<span class="charliteral">&apos;/&apos;</span>, start));
<a name="l00695"></a>00695     
<a name="l00696"></a>00696     <span class="keywordflow">if</span> (path === <span class="stringliteral">&quot;&quot;</span> &amp;&amp; charAt(0) === <span class="charliteral">&apos;/&apos;</span>)
<a name="l00697"></a>00697         <span class="keywordflow">return</span> <span class="charliteral">&apos;/&apos;</span>;
<a name="l00698"></a>00698 
<a name="l00699"></a>00699     <span class="keywordflow">return</span> path;
<a name="l00700"></a>00700 }
<a name="l00701"></a>00701 
<a name="l00702"></a><a class="code" href="class_c_p_string.html#a59029855eef295e7048807143b3ebb6d">00702</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#a59029855eef295e7048807143b3ebb6d">stringByStandardizingPath</a>
<a name="l00703"></a>00703 {
<a name="l00704"></a>00704     <span class="keywordflow">return</span> objj_standardize_path(<span class="keyword">self</span>);
<a name="l00705"></a>00705 }
<a name="l00706"></a>00706 
<a name="l00707"></a><a class="code" href="class_c_p_string.html#a7e00fa94f01b3e2efeb7fe5e2c6e2c03">00707</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#a7e00fa94f01b3e2efeb7fe5e2c6e2c03">copy</a>
<a name="l00708"></a>00708 {
<a name="l00709"></a>00709     <span class="keywordflow">return</span> <span class="keyword">new</span> String(<span class="keyword">self</span>);
<a name="l00710"></a>00710 }
<a name="l00711"></a>00711 
<a name="l00712"></a>00712 <span class="keyword">@end</span>
<a name="l00713"></a>00713 
<a name="l00714"></a>00714 
<a name="l00715"></a>00715 <span class="keyword">@implementation </span><a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a> (JSON)
<a name="l00716"></a>00716 
<a name="l00720"></a><a class="code" href="class_c_p_string.html#a87576009d7fab17ce04e0b990a3857cd">00720</a> + (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)JSONFromObject:(JSObject)anObject
<a name="l00721"></a>00721 {
<a name="l00722"></a>00722     <span class="keywordflow">return</span> JSON.stringify(anObject);
<a name="l00723"></a>00723 }
<a name="l00724"></a>00724 
<a name="l00728"></a><a class="code" href="class_c_p_string.html#a105bc15df0d53e744e05de3700ac1d30">00728</a> - (JSObject)<a class="code" href="class_c_p_string.html#a105bc15df0d53e744e05de3700ac1d30">objectFromJSON</a>
<a name="l00729"></a>00729 {
<a name="l00730"></a>00730     <span class="keywordflow">return</span> JSON.parse(<span class="keyword">self</span>);
<a name="l00731"></a>00731 }
<a name="l00732"></a>00732 
<a name="l00733"></a>00733 <span class="keyword">@end</span>
<a name="l00734"></a>00734 
<a name="l00735"></a>00735 
<a name="l00736"></a>00736 <span class="keyword">@implementation </span><a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a> (<a class="code" href="class_c_p_string.html#a7ff861f37a713ad67ab773ea2e2e061b">UUID</a>)
<a name="l00737"></a>00737 
<a name="l00741"></a><a class="code" href="class_c_p_string.html#a7ff861f37a713ad67ab773ea2e2e061b">00741</a> + (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)<a class="code" href="class_c_p_string.html#a7ff861f37a713ad67ab773ea2e2e061b">UUID</a>
<a name="l00742"></a>00742 {
<a name="l00743"></a>00743     var g = <span class="stringliteral">@&quot;&quot;</span>;
<a name="l00744"></a>00744     
<a name="l00745"></a>00745     <span class="keywordflow">for</span>(var i = 0; i &lt; 32; i++)
<a name="l00746"></a>00746         g += FLOOR(RAND() * 0xF).toString(0xF);
<a name="l00747"></a>00747     
<a name="l00748"></a>00748     <span class="keywordflow">return</span> g;
<a name="l00749"></a>00749 }
<a name="l00750"></a>00750 
<a name="l00751"></a>00751 <span class="keyword">@end</span>
<a name="l00752"></a>00752 
<a name="l00753"></a><a class="code" href="_c_p_string_8j.html#a509f19b8b33252128b46d22079932f27">00753</a> String.prototype.isa = <a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>;
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Apr 6 10:32:57 2010 for Cappuccino API by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_string_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:31 GMT -->
</html>