Source

cappuccino-docs / cappuccino docs / cappuccino.org / learn / documentation / _c_p_attributed_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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
<!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_attributed_string_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:29 GMT -->
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Cappuccino API: Foundation/CPAttributedString.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/CPAttributedString.j</h1><a href="_c_p_attributed_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"> * CPAttributedString.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 Ross Boucher.</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;CPString.j&quot;</span>
<a name="l00025"></a>00025 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPDictionary.j&quot;</span>
<a name="l00026"></a>00026 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPRange.j&quot;</span>
<a name="l00027"></a>00027 
<a name="l00044"></a><a class="code" href="class_c_p_attributed_string.html">00044</a> <span class="keyword">@implementation </span><a class="code" href="class_c_p_attributed_string.html" title="A mutable character string with attributes.">CPAttributedString</a> : <a class="code" href="class_c_p_object.html" title="The root class from which most classes are subclassed.">CPObject</a>
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046     <a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>    _string;
<a name="l00047"></a>00047     <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>     _rangeEntries;
<a name="l00048"></a>00048 }
<a name="l00049"></a>00049 
<a name="l00050"></a>00050 <span class="comment">//Creating an NSAttributedString Object</span>
<a name="l00056"></a><a class="code" href="class_c_p_attributed_string.html#ab4a83b775f69c364072edd226c69e2a8">00056</a> <span class="comment"></span>- (id)initWithString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00057"></a>00057 {
<a name="l00058"></a>00058     <span class="keywordflow">return</span> [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a1f9fe465d9cd8f21920a91e65d194bab">initWithString</a>:aString <a class="code" href="class_c_p_attributed_string.html#a1f9fe465d9cd8f21920a91e65d194bab">attributes</a>:nil];
<a name="l00059"></a>00059 }
<a name="l00060"></a>00060 
<a name="l00066"></a><a class="code" href="class_c_p_attributed_string.html#a021b26cb1e50b33013122bc3beadd690">00066</a> - (id)initWithAttributedString:(<a class="code" href="class_c_p_attributed_string.html" title="A mutable character string with attributes.">CPAttributedString</a>)aString
<a name="l00067"></a>00067 {
<a name="l00068"></a>00068     var <span class="keywordtype">string</span> = [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a1f9fe465d9cd8f21920a91e65d194bab">initWithString</a>:&quot;&quot; <a class="code" href="class_c_p_attributed_string.html#a1f9fe465d9cd8f21920a91e65d194bab">attributes</a>:nil];
<a name="l00069"></a>00069     
<a name="l00070"></a>00070     [<a class="code" href="class_c_p_attributed_string.html#a443e20fb6fb30a16f5fdaef64679ed95">string</a> setAttributedString:aString];
<a name="l00071"></a>00071     
<a name="l00072"></a>00072     <span class="keywordflow">return</span> string;
<a name="l00073"></a>00073 }
<a name="l00074"></a>00074 
<a name="l00083"></a><a class="code" href="class_c_p_attributed_string.html#a1f9fe465d9cd8f21920a91e65d194bab">00083</a> - (id)initWithString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString attributes:(<a class="code" href="class_c_p_dictionary.html" title="A mutable key-value pair collection.">CPDictionary</a>)attributes
<a name="l00084"></a>00084 {
<a name="l00085"></a>00085     <span class="keyword">self</span> = [<span class="keyword">super</span> init];
<a name="l00086"></a>00086     
<a name="l00087"></a>00087     <span class="keywordflow">if</span> (!attributes)
<a name="l00088"></a>00088         attributes = [<a class="code" href="class_c_p_dictionary.html" title="A mutable key-value pair collection.">CPDictionary</a> <a class="code" href="class_c_p_dictionary.html#af9820df885270d5200f27f9a539aca28">dictionary</a>];
<a name="l00089"></a>00089 
<a name="l00090"></a>00090     _string = <span class="stringliteral">&quot;&quot;</span>+aString;
<a name="l00091"></a>00091     _rangeEntries = [makeRangeEntry(CPMakeRange(0, _string.length), attributes)];
<a name="l00092"></a>00092 
<a name="l00093"></a>00093     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00094"></a>00094 }
<a name="l00095"></a>00095 
<a name="l00096"></a>00096 <span class="comment">//Retrieving Character Information</span>
<a name="l00102"></a><a class="code" href="class_c_p_attributed_string.html#a443e20fb6fb30a16f5fdaef64679ed95">00102</a> <span class="comment"></span>- (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)string
<a name="l00103"></a>00103 {
<a name="l00104"></a>00104     <span class="keywordflow">return</span> _string;
<a name="l00105"></a>00105 }
<a name="l00106"></a>00106 
<a name="l00112"></a><a class="code" href="class_c_p_attributed_string.html#add1f79eee6cfb9ed5fed01a560b9073a">00112</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)mutableString
<a name="l00113"></a>00113 {
<a name="l00114"></a>00114     <span class="keywordflow">return</span> [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a443e20fb6fb30a16f5fdaef64679ed95">string</a>];
<a name="l00115"></a>00115 }   
<a name="l00116"></a>00116 
<a name="l00122"></a><a class="code" href="class_c_p_attributed_string.html#a739ed5cfe475ebd1d02d072b901191b5">00122</a> - (unsigned)length
<a name="l00123"></a>00123 {
<a name="l00124"></a>00124     <span class="keywordflow">return</span> _string.length;
<a name="l00125"></a>00125 }
<a name="l00126"></a>00126 
<a name="l00127"></a>00127 <span class="comment">// private method</span>
<a name="l00128"></a>00128 - (unsigned)_indexOfEntryWithIndex:(<span class="keywordtype">unsigned</span>)anIndex
<a name="l00129"></a>00129 {
<a name="l00130"></a>00130     <span class="keywordflow">if</span> (anIndex &lt; 0 || anIndex &gt; _string.length || anIndex === undefined)
<a name="l00131"></a>00131         <span class="keywordflow">return</span> <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a>;
<a name="l00132"></a>00132 
<a name="l00133"></a>00133     <span class="comment">//find the range entry that contains anIndex.</span>
<a name="l00134"></a>00134     var sortFunction = function(index, entry)
<a name="l00135"></a>00135     {
<a name="l00136"></a>00136         <span class="comment">//index is the character index we&apos;re searching for, while range is the actual range entry we&apos;re comparing against</span>
<a name="l00137"></a>00137         <span class="keywordflow">if</span> (<a class="code" href="group__foundation.html#ga11d8b85f5a9d54a56c269d269745c671">CPLocationInRange</a>(index, entry.range))
<a name="l00138"></a>00138             <span class="keywordflow">return</span> <a class="code" href="_c_p_obj_j_runtime_8j.html#af6563f83ad093188bcbdba78aa1848c5">CPOrderedSame</a>;
<a name="l00139"></a>00139         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(entry.range) &lt;= index)
<a name="l00140"></a>00140             <span class="keywordflow">return</span> <a class="code" href="_c_p_obj_j_runtime_8j.html#aad9efd5d7748d296944239adb552f67c">CPOrderedDescending</a>;
<a name="l00141"></a>00141         <span class="keywordflow">else</span>
<a name="l00142"></a>00142             <span class="keywordflow">return</span> <a class="code" href="_c_p_obj_j_runtime_8j.html#a3e9b85c1be28d3092262626ffcf41993">CPOrderedAscending</a>;
<a name="l00143"></a>00143     }
<a name="l00144"></a>00144 
<a name="l00145"></a>00145     <span class="keywordflow">return</span> [_rangeEntries indexOfObject:anIndex sortedByFunction:sortFunction];
<a name="l00146"></a>00146 }
<a name="l00147"></a>00147 
<a name="l00148"></a>00148 <span class="comment">//Retrieving Attribute Information</span>
<a name="l00167"></a><a class="code" href="class_c_p_attributed_string.html#aa74aacde4d6d14e0a73a0860dff6c2db">00167</a> <span class="comment"></span>- (<a class="code" href="class_c_p_dictionary.html" title="A mutable key-value pair collection.">CPDictionary</a>)attributesAtIndex:(<span class="keywordtype">unsigned</span>)anIndex effectiveRange:(CPRangePointer)aRange
<a name="l00168"></a>00168 {
<a name="l00169"></a>00169     <span class="comment">//find the range entry that contains anIndex.</span>
<a name="l00170"></a>00170     var entryIndex = [<span class="keyword">self</span> _indexOfEntryWithIndex:anIndex];
<a name="l00171"></a>00171 
<a name="l00172"></a>00172     <span class="keywordflow">if</span> (entryIndex == <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a>)
<a name="l00173"></a>00173         <span class="keywordflow">return</span> nil;
<a name="l00174"></a>00174 
<a name="l00175"></a>00175     var matchingRange = _rangeEntries[entryIndex];
<a name="l00176"></a>00176     <span class="keywordflow">if</span> (aRange)
<a name="l00177"></a>00177     {
<a name="l00178"></a>00178         aRange.location = matchingRange.range.location;
<a name="l00179"></a>00179         aRange.length = matchingRange.range.length;
<a name="l00180"></a>00180     }
<a name="l00181"></a>00181     
<a name="l00182"></a>00182     <span class="keywordflow">return</span> matchingRange.attributes;
<a name="l00183"></a>00183 }
<a name="l00184"></a>00184 
<a name="l00206"></a><a class="code" href="class_c_p_attributed_string.html#a943cea297edb8879bbdc1d3f6e98b52c">00206</a> - (<a class="code" href="class_c_p_dictionary.html" title="A mutable key-value pair collection.">CPDictionary</a>)attributesAtIndex:(<span class="keywordtype">unsigned</span>)anIndex longestEffectiveRange:(CPRangePointer)aRange inRange:(CPRange)rangeLimit
<a name="l00207"></a>00207 {    
<a name="l00208"></a>00208     var startingEntryIndex = [<span class="keyword">self</span> _indexOfEntryWithIndex:anIndex];
<a name="l00209"></a>00209 
<a name="l00210"></a>00210     <span class="keywordflow">if</span> (startingEntryIndex == <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a>)
<a name="l00211"></a>00211         <span class="keywordflow">return</span> nil;
<a name="l00212"></a>00212     
<a name="l00213"></a>00213     <span class="keywordflow">if</span> (!aRange)
<a name="l00214"></a>00214         <span class="keywordflow">return</span> _rangeEntries[startingEntryIndex].attributes;
<a name="l00215"></a>00215 
<a name="l00216"></a>00216     <span class="keywordflow">if</span> (<a class="code" href="group__foundation.html#ga27da7cc6d5e82effc742767a75efbe87">CPRangeInRange</a>(_rangeEntries[startingEntryIndex].range, rangeLimit))
<a name="l00217"></a>00217     {
<a name="l00218"></a>00218         aRange.location = rangeLimit.location;
<a name="l00219"></a>00219         aRange.length = rangeLimit.length;
<a name="l00220"></a>00220         
<a name="l00221"></a>00221         <span class="keywordflow">return</span> _rangeEntries[startingEntryIndex].attributes;
<a name="l00222"></a>00222     }
<a name="l00223"></a>00223 
<a name="l00224"></a>00224     <span class="comment">//scan backwards</span>
<a name="l00225"></a>00225     var nextRangeIndex = startingEntryIndex - 1,
<a name="l00226"></a>00226         currentEntry = _rangeEntries[startingEntryIndex],
<a name="l00227"></a>00227         comparisonDict = currentEntry.attributes;
<a name="l00228"></a>00228 
<a name="l00229"></a>00229     <span class="keywordflow">while</span> (nextRangeIndex &gt;= 0)
<a name="l00230"></a>00230     {
<a name="l00231"></a>00231         var nextEntry = _rangeEntries[nextRangeIndex];
<a name="l00232"></a>00232 
<a name="l00233"></a>00233         <span class="keywordflow">if</span> (<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(nextEntry.range) &gt; rangeLimit.location &amp;&amp; [nextEntry.attributes isEqualToDictionary:comparisonDict])
<a name="l00234"></a>00234         {
<a name="l00235"></a>00235             currentEntry = nextEntry;
<a name="l00236"></a>00236             nextRangeIndex--;
<a name="l00237"></a>00237         }
<a name="l00238"></a>00238         <span class="keywordflow">else</span>
<a name="l00239"></a>00239             <span class="keywordflow">break</span>;
<a name="l00240"></a>00240     }
<a name="l00241"></a>00241 
<a name="l00242"></a>00242     aRange.location = <a class="code" href="_c_p_obj_j_runtime_8j.html#a45f5f88d061da0c18bcb6b6a854fe898">MAX</a>(currentEntry.range.location, rangeLimit.location);
<a name="l00243"></a>00243 
<a name="l00244"></a>00244     <span class="comment">//scan forwards</span>
<a name="l00245"></a>00245     currentEntry = _rangeEntries[startingEntryIndex];
<a name="l00246"></a>00246     nextRangeIndex = startingEntryIndex + 1;
<a name="l00247"></a>00247 
<a name="l00248"></a>00248     <span class="keywordflow">while</span> (nextRangeIndex &lt; _rangeEntries.length)
<a name="l00249"></a>00249     {
<a name="l00250"></a>00250         var nextEntry = _rangeEntries[nextRangeIndex];
<a name="l00251"></a>00251 
<a name="l00252"></a>00252         <span class="keywordflow">if</span> (nextEntry.range.location &lt; <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(rangeLimit) &amp;&amp; [nextEntry.attributes isEqualToDictionary:comparisonDict])
<a name="l00253"></a>00253         {
<a name="l00254"></a>00254             currentEntry = nextEntry;
<a name="l00255"></a>00255             nextRangeIndex++;
<a name="l00256"></a>00256         }
<a name="l00257"></a>00257         <span class="keywordflow">else</span>
<a name="l00258"></a>00258             <span class="keywordflow">break</span>;
<a name="l00259"></a>00259     }
<a name="l00260"></a>00260         
<a name="l00261"></a>00261     aRange.length = <a class="code" href="_c_p_obj_j_runtime_8j.html#a4fca277171215842609dc38a6f0c19fb">MIN</a>(<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(currentEntry.range), <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(rangeLimit)) - aRange.location;
<a name="l00262"></a>00262 
<a name="l00263"></a>00263     <span class="keywordflow">return</span> comparisonDict;
<a name="l00264"></a>00264 }
<a name="l00265"></a>00265 
<a name="l00282"></a><a class="code" href="class_c_p_attributed_string.html#ad5d7f9232c6d70bed4de8226384f04e8">00282</a> - (id)attribute:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)attribute atIndex:(<span class="keywordtype">unsigned</span>)index effectiveRange:(CPRangePointer)aRange
<a name="l00283"></a>00283 {
<a name="l00284"></a>00284     <span class="keywordflow">if</span> (!attribute)
<a name="l00285"></a>00285     {
<a name="l00286"></a>00286         <span class="keywordflow">if</span> (aRange)
<a name="l00287"></a>00287         {
<a name="l00288"></a>00288             aRange.location = 0;
<a name="l00289"></a>00289             aRange.length = _string.length;
<a name="l00290"></a>00290         }
<a name="l00291"></a>00291 
<a name="l00292"></a>00292         <span class="keywordflow">return</span> nil;
<a name="l00293"></a>00293     }
<a name="l00294"></a>00294 
<a name="l00295"></a>00295     <span class="keywordflow">return</span> [[<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#aa74aacde4d6d14e0a73a0860dff6c2db">attributesAtIndex</a>:index <a class="code" href="class_c_p_attributed_string.html#aa74aacde4d6d14e0a73a0860dff6c2db">effectiveRange</a>:aRange] <a class="code" href="class_c_p_dictionary.html#a1f7a5fe026f10c04bf41dc9327496f59">valueForKey</a>:attribute];
<a name="l00296"></a>00296 }
<a name="l00297"></a>00297 
<a name="l00319"></a><a class="code" href="class_c_p_attributed_string.html#aa926bb8abc3307adfc55675760259be7">00319</a> - (id)attribute:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)attribute atIndex:(<span class="keywordtype">unsigned</span>)anIndex longestEffectiveRange:(CPRangePointer)aRange inRange:(CPRange)rangeLimit
<a name="l00320"></a>00320 {
<a name="l00321"></a>00321     <span class="comment">//find the range entry that contains anIndex.</span>
<a name="l00322"></a>00322     var startingEntryIndex = [<span class="keyword">self</span> _indexOfEntryWithIndex:anIndex];
<a name="l00323"></a>00323     
<a name="l00324"></a>00324     <span class="keywordflow">if</span> (startingEntryIndex == <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a> || !attribute)
<a name="l00325"></a>00325         <span class="keywordflow">return</span> nil;
<a name="l00326"></a>00326 
<a name="l00327"></a>00327     <span class="keywordflow">if</span> (!aRange)
<a name="l00328"></a>00328         <span class="keywordflow">return</span> [_rangeEntries[startingEntryIndex].attributes objectForKey:attribute];
<a name="l00329"></a>00329 
<a name="l00330"></a>00330     <span class="keywordflow">if</span> (<a class="code" href="group__foundation.html#ga27da7cc6d5e82effc742767a75efbe87">CPRangeInRange</a>(_rangeEntries[startingEntryIndex].range, rangeLimit))
<a name="l00331"></a>00331     {
<a name="l00332"></a>00332         aRange.location = rangeLimit.location;
<a name="l00333"></a>00333         aRange.length = rangeLimit.length;
<a name="l00334"></a>00334         
<a name="l00335"></a>00335         <span class="keywordflow">return</span> [_rangeEntries[startingEntryIndex].attributes objectForKey:attribute];
<a name="l00336"></a>00336     }
<a name="l00337"></a>00337 
<a name="l00338"></a>00338     <span class="comment">//scan backwards</span>
<a name="l00339"></a>00339     var nextRangeIndex = startingEntryIndex - 1,
<a name="l00340"></a>00340         currentEntry = _rangeEntries[startingEntryIndex],
<a name="l00341"></a>00341         comparisonAttribute = [currentEntry.attributes objectForKey:attribute];
<a name="l00342"></a>00342 
<a name="l00343"></a>00343     <span class="keywordflow">while</span> (nextRangeIndex &gt;= 0)
<a name="l00344"></a>00344     {
<a name="l00345"></a>00345         var nextEntry = _rangeEntries[nextRangeIndex];
<a name="l00346"></a>00346 
<a name="l00347"></a>00347         <span class="keywordflow">if</span> (<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(nextEntry.range) &gt; rangeLimit.location &amp;&amp; isEqual(comparisonAttribute, [nextEntry.attributes objectForKey:attribute]))
<a name="l00348"></a>00348         {
<a name="l00349"></a>00349             currentEntry = nextEntry;
<a name="l00350"></a>00350             nextRangeIndex--;
<a name="l00351"></a>00351         }
<a name="l00352"></a>00352         <span class="keywordflow">else</span>
<a name="l00353"></a>00353             <span class="keywordflow">break</span>;
<a name="l00354"></a>00354     }
<a name="l00355"></a>00355 
<a name="l00356"></a>00356     aRange.location = <a class="code" href="_c_p_obj_j_runtime_8j.html#a45f5f88d061da0c18bcb6b6a854fe898">MAX</a>(currentEntry.range.location, rangeLimit.location);
<a name="l00357"></a>00357 
<a name="l00358"></a>00358     <span class="comment">//scan forwards</span>
<a name="l00359"></a>00359     currentEntry = _rangeEntries[startingEntryIndex];
<a name="l00360"></a>00360     nextRangeIndex = startingEntryIndex + 1;
<a name="l00361"></a>00361 
<a name="l00362"></a>00362     <span class="keywordflow">while</span> (nextRangeIndex &lt; _rangeEntries.length)
<a name="l00363"></a>00363     {
<a name="l00364"></a>00364         var nextEntry = _rangeEntries[nextRangeIndex];
<a name="l00365"></a>00365 
<a name="l00366"></a>00366         <span class="keywordflow">if</span> (nextEntry.range.location &lt; <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(rangeLimit) &amp;&amp; isEqual(comparisonAttribute, [nextEntry.attributes objectForKey:attribute]))
<a name="l00367"></a>00367         {
<a name="l00368"></a>00368             currentEntry = nextEntry;
<a name="l00369"></a>00369             nextRangeIndex++;
<a name="l00370"></a>00370         }
<a name="l00371"></a>00371         <span class="keywordflow">else</span>
<a name="l00372"></a>00372             <span class="keywordflow">break</span>;
<a name="l00373"></a>00373     }
<a name="l00374"></a>00374         
<a name="l00375"></a>00375     aRange.length = <a class="code" href="_c_p_obj_j_runtime_8j.html#a4fca277171215842609dc38a6f0c19fb">MIN</a>(<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(currentEntry.range), <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(rangeLimit)) - aRange.location;
<a name="l00376"></a>00376 
<a name="l00377"></a>00377     <span class="keywordflow">return</span> comparisonAttribute;
<a name="l00378"></a>00378 }
<a name="l00379"></a>00379 
<a name="l00380"></a>00380 <span class="comment">//Comparing Attributed Strings</span>
<a name="l00387"></a><a class="code" href="class_c_p_attributed_string.html#a38dfa968a31de15001abd748430b08dd">00387</a> <span class="comment"></span>- (BOOL)isEqualToAttributedString:(<a class="code" href="class_c_p_attributed_string.html" title="A mutable character string with attributes.">CPAttributedString</a>)aString
<a name="l00388"></a>00388 {
<a name="l00389"></a>00389         <span class="keywordflow">if</span>(!aString)
<a name="l00390"></a>00390                 <span class="keywordflow">return</span> NO;
<a name="l00391"></a>00391 
<a name="l00392"></a>00392         <span class="keywordflow">if</span>(_string != [aString <span class="keywordtype">string</span>])
<a name="l00393"></a>00393                 <span class="keywordflow">return</span> NO;
<a name="l00394"></a>00394 
<a name="l00395"></a>00395     var myRange = <a class="code" href="group__foundation.html#ga377fec0972facd19d72b8abcffcdb362">CPMakeRange</a>(),
<a name="l00396"></a>00396         comparisonRange = <a class="code" href="group__foundation.html#ga377fec0972facd19d72b8abcffcdb362">CPMakeRange</a>(),
<a name="l00397"></a>00397         myAttributes = [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#aa74aacde4d6d14e0a73a0860dff6c2db">attributesAtIndex</a>:0 <a class="code" href="class_c_p_attributed_string.html#aa74aacde4d6d14e0a73a0860dff6c2db">effectiveRange</a>:myRange],
<a name="l00398"></a>00398         comparisonAttributes = [aString <a class="code" href="class_c_p_attributed_string.html#aa74aacde4d6d14e0a73a0860dff6c2db">attributesAtIndex</a>:0 <a class="code" href="class_c_p_attributed_string.html#aa74aacde4d6d14e0a73a0860dff6c2db">effectiveRange</a>:comparisonRange],
<a name="l00399"></a>00399         length = _string.length;
<a name="l00400"></a>00400 
<a name="l00401"></a>00401     <span class="keywordflow">while</span> (<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(<a class="code" href="group__foundation.html#gabba35730ec5375f5e23a78da6322f4c9">CPUnionRange</a>(myRange, comparisonRange)) &lt; length)
<a name="l00402"></a>00402     {
<a name="l00403"></a>00403         <span class="keywordflow">if</span> (<a class="code" href="group__foundation.html#ga75c00938ebca2b401aacd063802fdde4">CPIntersectionRange</a>(myRange, comparisonRange).length &gt; 0 &amp;&amp; ![myAttributes isEqualToDictionary:comparisonAttributes])
<a name="l00404"></a>00404             <span class="keywordflow">return</span> NO;
<a name="l00405"></a>00405         <span class="keywordflow">if</span> (<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(myRange) &lt; <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(comparisonRange))
<a name="l00406"></a>00406             myAttributes = [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#aa74aacde4d6d14e0a73a0860dff6c2db">attributesAtIndex</a>:CPMaxRange(myRange) <a class="code" href="class_c_p_attributed_string.html#aa74aacde4d6d14e0a73a0860dff6c2db">effectiveRange</a>:myRange];
<a name="l00407"></a>00407         <span class="keywordflow">else</span>
<a name="l00408"></a>00408             comparisonAttributes = [aString <a class="code" href="class_c_p_attributed_string.html#aa74aacde4d6d14e0a73a0860dff6c2db">attributesAtIndex</a>:CPMaxRange(comparisonRange) <a class="code" href="class_c_p_attributed_string.html#aa74aacde4d6d14e0a73a0860dff6c2db">effectiveRange</a>:comparisonRange];
<a name="l00409"></a>00409     }
<a name="l00410"></a>00410     
<a name="l00411"></a>00411     <span class="keywordflow">return</span> YES;
<a name="l00412"></a>00412 }
<a name="l00413"></a>00413 
<a name="l00421"></a><a class="code" href="class_c_p_attributed_string.html#a4c2e2112f80871865a106fa4ea0a782b">00421</a> - (BOOL)isEqual:(<span class="keywordtype">id</span>)anObject
<a name="l00422"></a>00422 {
<a name="l00423"></a>00423         <span class="keywordflow">if</span> (anObject == <span class="keyword">self</span>)
<a name="l00424"></a>00424                 <span class="keywordflow">return</span> YES;
<a name="l00425"></a>00425                 
<a name="l00426"></a>00426         <span class="keywordflow">if</span> ([anObject isKindOfClass:[<span class="keyword">self</span> <span class="keyword">class</span>]])
<a name="l00427"></a>00427                 <span class="keywordflow">return</span> [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a38dfa968a31de15001abd748430b08dd">isEqualToAttributedString</a>:anObject];
<a name="l00428"></a>00428                 
<a name="l00429"></a>00429         <span class="keywordflow">return</span> NO;
<a name="l00430"></a>00430 }
<a name="l00431"></a>00431 
<a name="l00432"></a>00432 <span class="comment">//Extracting a Substring</span>
<a name="l00440"></a><a class="code" href="class_c_p_attributed_string.html#aaaea6bce842968710960d921ad6cd23c">00440</a> <span class="comment"></span>- (<a class="code" href="class_c_p_attributed_string.html" title="A mutable character string with attributes.">CPAttributedString</a>)attributedSubstringFromRange:(CPRange)aRange
<a name="l00441"></a>00441 {
<a name="l00442"></a>00442     <span class="keywordflow">if</span> (!aRange || <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(aRange) &gt; _string.length || aRange.location &lt; 0)
<a name="l00443"></a>00443         [<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>:CPRangeException 
<a name="l00444"></a>00444                     <a class="code" href="class_c_p_exception.html#ac8f34bd11868822e26a7b952810128b8">reason</a>:&quot;tried to get attributedSubstring for an invalid range: &quot;+(aRange?CPStringFromRange(aRange):&quot;nil&quot;)];
<a name="l00445"></a>00445 
<a name="l00446"></a>00446     var newString = [[<a class="code" href="class_c_p_attributed_string.html" title="A mutable character string with attributes.">CPAttributedString</a> alloc] initWithString:_string.substring(aRange.location, CPMaxRange(aRange))],
<a name="l00447"></a>00447         entryIndex = [<span class="keyword">self</span> _indexOfEntryWithIndex:aRange.location],
<a name="l00448"></a>00448         currentRangeEntry = _rangeEntries[entryIndex],
<a name="l00449"></a>00449         lastIndex = <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(aRange);
<a name="l00450"></a>00450 
<a name="l00451"></a>00451     newString._rangeEntries = [];
<a name="l00452"></a>00452     
<a name="l00453"></a>00453     <span class="keywordflow">while</span> (currentRangeEntry &amp;&amp; <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(currentRangeEntry.range) &lt; lastIndex)
<a name="l00454"></a>00454     {
<a name="l00455"></a>00455         var newEntry = copyRangeEntry(currentRangeEntry);
<a name="l00456"></a>00456         newEntry.range.location -= aRange.location;
<a name="l00457"></a>00457 
<a name="l00458"></a>00458         <span class="keywordflow">if</span> (newEntry.range.location &lt; 0)
<a name="l00459"></a>00459         {
<a name="l00460"></a>00460             newEntry.range.length += newEntry.range.location;
<a name="l00461"></a>00461             newEntry.range.location = 0;
<a name="l00462"></a>00462         }
<a name="l00463"></a>00463 
<a name="l00464"></a>00464         newString._rangeEntries.push(newEntry);
<a name="l00465"></a>00465         currentRangeEntry = _rangeEntries[++entryIndex];
<a name="l00466"></a>00466     }
<a name="l00467"></a>00467 
<a name="l00468"></a>00468     <span class="keywordflow">if</span> (currentRangeEntry)
<a name="l00469"></a>00469     {
<a name="l00470"></a>00470         var newRangeEntry = copyRangeEntry(currentRangeEntry);
<a name="l00471"></a>00471     
<a name="l00472"></a>00472         newRangeEntry.range.length = <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(aRange) - newRangeEntry.range.location;
<a name="l00473"></a>00473         newRangeEntry.range.location -= aRange.location;
<a name="l00474"></a>00474         
<a name="l00475"></a>00475         <span class="keywordflow">if</span> (newRangeEntry.range.location &lt; 0)
<a name="l00476"></a>00476         {
<a name="l00477"></a>00477             newRangeEntry.range.length += newRangeEntry.range.location;
<a name="l00478"></a>00478             newRangeEntry.range.location = 0;
<a name="l00479"></a>00479         }
<a name="l00480"></a>00480 
<a name="l00481"></a>00481         newString._rangeEntries.push(newRangeEntry);
<a name="l00482"></a>00482     }
<a name="l00483"></a>00483     
<a name="l00484"></a>00484     <span class="keywordflow">return</span> newString;
<a name="l00485"></a>00485 }
<a name="l00486"></a>00486 
<a name="l00487"></a>00487 <span class="comment">//Changing Characters</span>
<a name="l00502"></a><a class="code" href="class_c_p_attributed_string.html#a2fbad89e18aea895318ee3c3b5e515dd">00502</a> <span class="comment"></span>- (void)replaceCharactersInRange:(CPRange)aRange withString:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aString
<a name="l00503"></a>00503 {
<a name="l00504"></a>00504     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#af03c792e2666774116d7030ee43df31b">beginEditing</a>];
<a name="l00505"></a>00505 
<a name="l00506"></a>00506     <span class="keywordflow">if</span> (!aString)
<a name="l00507"></a>00507         aString = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00508"></a>00508         
<a name="l00509"></a>00509     var startingIndex = [<span class="keyword">self</span> _indexOfEntryWithIndex:aRange.location],
<a name="l00510"></a>00510         startingRangeEntry = _rangeEntries[startingIndex],
<a name="l00511"></a>00511         endingIndex = [<span class="keyword">self</span> _indexOfEntryWithIndex:MAX(CPMaxRange(aRange)-1, 0)],
<a name="l00512"></a>00512         endingRangeEntry = _rangeEntries[endingIndex],
<a name="l00513"></a>00513         additionalLength = aString.<a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a> - aRange.length;
<a name="l00514"></a>00514 
<a name="l00515"></a>00515     _string = _string.substring(0, aRange.location) + aString + _string.substring(<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(aRange));
<a name="l00516"></a>00516 
<a name="l00517"></a>00517     <span class="keywordflow">if</span> (startingIndex == endingIndex)
<a name="l00518"></a>00518         startingRangeEntry.range.<a class="code" href="class_c_p_string.html#a995ca4d2f7167db0da2fad02a444ec73">length</a> += additionalLength;
<a name="l00519"></a>00519     <span class="keywordflow">else</span>
<a name="l00520"></a>00520     {
<a name="l00521"></a>00521         endingRangeEntry.range.length = <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(endingRangeEntry.range) - <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(aRange);
<a name="l00522"></a>00522         endingRangeEntry.range.location = <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(aRange);
<a name="l00523"></a>00523 
<a name="l00524"></a>00524         startingRangeEntry.range.length = <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(aRange) - startingRangeEntry.range.location;
<a name="l00525"></a>00525 
<a name="l00526"></a>00526         _rangeEntries.splice(startingIndex, endingIndex - startingIndex);
<a name="l00527"></a>00527     }
<a name="l00528"></a>00528 
<a name="l00529"></a>00529     endingIndex = startingIndex + 1;
<a name="l00530"></a>00530     
<a name="l00531"></a>00531     <span class="keywordflow">while</span>(endingIndex &lt; _rangeEntries.length)
<a name="l00532"></a>00532         _rangeEntries[endingIndex++].range.location+=additionalLength;
<a name="l00533"></a>00533     
<a name="l00534"></a>00534     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a78a167606f00439f78f1fa5b2f384935">endEditing</a>];
<a name="l00535"></a>00535 }
<a name="l00536"></a>00536 
<a name="l00541"></a><a class="code" href="class_c_p_attributed_string.html#abd8d8d8b5051572a07dbbfbdccf02e3f">00541</a> - (void)deleteCharactersInRange:(CPRange)aRange
<a name="l00542"></a>00542 {
<a name="l00543"></a>00543     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a2fbad89e18aea895318ee3c3b5e515dd">replaceCharactersInRange</a>:aRange <a class="code" href="class_c_p_attributed_string.html#a2fbad89e18aea895318ee3c3b5e515dd">withString</a>:nil];
<a name="l00544"></a>00544 }
<a name="l00545"></a>00545 
<a name="l00546"></a>00546 <span class="comment">//Changing Attributes</span>
<a name="l00558"></a><a class="code" href="class_c_p_attributed_string.html#a5377c9b24073ecd708ce43e4ef949bdd">00558</a> <span class="comment"></span>- (void)setAttributes:(<a class="code" href="class_c_p_dictionary.html" title="A mutable key-value pair collection.">CPDictionary</a>)aDictionary range:(CPRange)aRange
<a name="l00559"></a>00559 {
<a name="l00560"></a>00560     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#af03c792e2666774116d7030ee43df31b">beginEditing</a>];
<a name="l00561"></a>00561 
<a name="l00562"></a>00562     var startingEntryIndex = [<span class="keyword">self</span> _indexOfRangeEntryForIndex:aRange.location splitOnMaxIndex:YES],
<a name="l00563"></a>00563         endingEntryIndex = [<span class="keyword">self</span> _indexOfRangeEntryForIndex:CPMaxRange(aRange) splitOnMaxIndex:YES],
<a name="l00564"></a>00564         current = startingEntryIndex;
<a name="l00565"></a>00565 
<a name="l00566"></a>00566     <span class="keywordflow">if</span> (endingEntryIndex == <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a>)
<a name="l00567"></a>00567         endingEntryIndex = _rangeEntries.length;
<a name="l00568"></a>00568 
<a name="l00569"></a>00569     <span class="keywordflow">while</span> (current &lt; endingEntryIndex)
<a name="l00570"></a>00570         _rangeEntries[current++].attributes = [aDictionary <a class="code" href="class_c_p_dictionary.html#a735a2d2daeff5890c6246aafe9f3edff">copy</a>];
<a name="l00571"></a>00571 
<a name="l00572"></a>00572     <span class="comment">//necessary?</span>
<a name="l00573"></a>00573     [<span class="keyword">self</span> _coalesceRangeEntriesFromIndex:startingEntryIndex toIndex:endingEntryIndex];
<a name="l00574"></a>00574 
<a name="l00575"></a>00575     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a78a167606f00439f78f1fa5b2f384935">endEditing</a>];
<a name="l00576"></a>00576 }
<a name="l00577"></a>00577 
<a name="l00588"></a><a class="code" href="class_c_p_attributed_string.html#ab9dcfab9c2944c972f8c15ff86695450">00588</a> - (void)addAttributes:(<a class="code" href="class_c_p_dictionary.html" title="A mutable key-value pair collection.">CPDictionary</a>)aDictionary range:(CPRange)aRange
<a name="l00589"></a>00589 {
<a name="l00590"></a>00590     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#af03c792e2666774116d7030ee43df31b">beginEditing</a>];
<a name="l00591"></a>00591 
<a name="l00592"></a>00592     var startingEntryIndex = [<span class="keyword">self</span> _indexOfRangeEntryForIndex:aRange.location splitOnMaxIndex:YES],
<a name="l00593"></a>00593         endingEntryIndex = [<span class="keyword">self</span> _indexOfRangeEntryForIndex:CPMaxRange(aRange) splitOnMaxIndex:YES],
<a name="l00594"></a>00594         current = startingEntryIndex;
<a name="l00595"></a>00595 
<a name="l00596"></a>00596     <span class="keywordflow">if</span> (endingEntryIndex == <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a>)
<a name="l00597"></a>00597         endingEntryIndex = _rangeEntries.length;
<a name="l00598"></a>00598 
<a name="l00599"></a>00599     <span class="keywordflow">while</span> (current &lt; endingEntryIndex)
<a name="l00600"></a>00600     {
<a name="l00601"></a>00601         var keys = [aDictionary <a class="code" href="class_c_p_dictionary.html#ac03bded1a55ad59569cd6e32820f67e0">allKeys</a>],
<a name="l00602"></a>00602             count = [keys count];
<a name="l00603"></a>00603             
<a name="l00604"></a>00604         <span class="keywordflow">while</span> (count--)
<a name="l00605"></a>00605             [_rangeEntries[current].attributes setObject:[aDictionary <a class="code" href="class_c_p_dictionary.html#ab4aaab7d240d27cf2f32c60bffc13d9e">objectForKey</a>:keys[count]] <a class="code" href="class_c_p_dictionary.html#af045c97d07b1d7313504b86728f15d09">forKey</a>:keys[count]];
<a name="l00606"></a>00606 
<a name="l00607"></a>00607         current++;
<a name="l00608"></a>00608     }
<a name="l00609"></a>00609 
<a name="l00610"></a>00610     <span class="comment">//necessary?</span>
<a name="l00611"></a>00611     [<span class="keyword">self</span> _coalesceRangeEntriesFromIndex:startingEntryIndex toIndex:endingEntryIndex];
<a name="l00612"></a>00612 
<a name="l00613"></a>00613     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a78a167606f00439f78f1fa5b2f384935">endEditing</a>];
<a name="l00614"></a>00614 }
<a name="l00615"></a>00615 
<a name="l00628"></a><a class="code" href="class_c_p_attributed_string.html#aa1384a7e20f76510b26eed296ab9aa34">00628</a> - (void)addAttribute:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)anAttribute value:(<span class="keywordtype">id</span>)aValue range:(CPRange)aRange
<a name="l00629"></a>00629 {
<a name="l00630"></a>00630     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#ab9dcfab9c2944c972f8c15ff86695450">addAttributes</a>:[<a class="code" href="class_c_p_dictionary.html" title="A mutable key-value pair collection.">CPDictionary</a> <a class="code" href="class_c_p_dictionary.html#ae3b91d744723e22ea217f968380c3173">dictionaryWithObject</a>:aValue <a class="code" href="class_c_p_dictionary.html#ae3b91d744723e22ea217f968380c3173">forKey</a>:anAttribute] <a class="code" href="class_c_p_attributed_string.html#ab9dcfab9c2944c972f8c15ff86695450">range</a>:aRange];
<a name="l00631"></a>00631 }
<a name="l00632"></a>00632 
<a name="l00639"></a><a class="code" href="class_c_p_attributed_string.html#aee1f5315af1180f29115a4f270dc7238">00639</a> - (void)removeAttribute:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)anAttribute range:(CPRange)aRange
<a name="l00640"></a>00640 {
<a name="l00641"></a>00641     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#af03c792e2666774116d7030ee43df31b">beginEditing</a>];
<a name="l00642"></a>00642 
<a name="l00643"></a>00643     var startingEntryIndex = [<span class="keyword">self</span> _indexOfRangeEntryForIndex:aRange.location splitOnMaxIndex:YES],
<a name="l00644"></a>00644         endingEntryIndex = [<span class="keyword">self</span> _indexOfRangeEntryForIndex:CPMaxRange(aRange) splitOnMaxIndex:YES],
<a name="l00645"></a>00645         current = startingEntryIndex;
<a name="l00646"></a>00646 
<a name="l00647"></a>00647     <span class="keywordflow">if</span> (endingEntryIndex == <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a>)
<a name="l00648"></a>00648         endingEntryIndex = _rangeEntries.length;
<a name="l00649"></a>00649 
<a name="l00650"></a>00650     <span class="keywordflow">while</span> (current &lt; endingEntryIndex)
<a name="l00651"></a>00651         [_rangeEntries[current++].attributes removeObjectForKey:anAttribute];
<a name="l00652"></a>00652 
<a name="l00653"></a>00653     <span class="comment">//necessary?</span>
<a name="l00654"></a>00654     [<span class="keyword">self</span> _coalesceRangeEntriesFromIndex:startingEntryIndex toIndex:endingEntryIndex];
<a name="l00655"></a>00655 
<a name="l00656"></a>00656     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a78a167606f00439f78f1fa5b2f384935">endEditing</a>];
<a name="l00657"></a>00657 }
<a name="l00658"></a>00658 
<a name="l00659"></a>00659 <span class="comment">//Changing Characters and Attributes</span>
<a name="l00665"></a><a class="code" href="class_c_p_attributed_string.html#adf87ae68982cc59b80c0f9a8fc54709f">00665</a> <span class="comment"></span>- (void)appendAttributedString:(<a class="code" href="class_c_p_attributed_string.html" title="A mutable character string with attributes.">CPAttributedString</a>)aString
<a name="l00666"></a>00666 {
<a name="l00667"></a>00667     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a5b8893f059d055cacf2953344155315b">insertAttributedString</a>:aString <a class="code" href="class_c_p_attributed_string.html#a5b8893f059d055cacf2953344155315b">atIndex</a>:_string.length];
<a name="l00668"></a>00668 }
<a name="l00669"></a>00669 
<a name="l00679"></a><a class="code" href="class_c_p_attributed_string.html#a5b8893f059d055cacf2953344155315b">00679</a> - (void)insertAttributedString:(<a class="code" href="class_c_p_attributed_string.html" title="A mutable character string with attributes.">CPAttributedString</a>)aString atIndex:(<span class="keywordtype">unsigned</span>)anIndex
<a name="l00680"></a>00680 {
<a name="l00681"></a>00681     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#af03c792e2666774116d7030ee43df31b">beginEditing</a>];
<a name="l00682"></a>00682 
<a name="l00683"></a>00683     <span class="keywordflow">if</span> (anIndex &lt; 0 || anIndex &gt; [<span class="keyword">self</span> length])
<a name="l00684"></a>00684         [<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>:CPRangeException <a class="code" href="class_c_p_exception.html#ac8f34bd11868822e26a7b952810128b8">reason</a>:&quot;tried to insert attributed string at an invalid index: &quot;+anIndex];
<a name="l00685"></a>00685 
<a name="l00686"></a>00686     var entryIndexOfNextEntry = [<span class="keyword">self</span> _indexOfRangeEntryForIndex:anIndex splitOnMaxIndex:YES],
<a name="l00687"></a>00687         otherRangeEntries = aString._rangeEntries,
<a name="l00688"></a>00688         length = [aString <a class="code" href="class_c_p_attributed_string.html#a739ed5cfe475ebd1d02d072b901191b5">length</a>];
<a name="l00689"></a>00689 
<a name="l00690"></a>00690     <span class="keywordflow">if</span> (entryIndexOfNextEntry == <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a>)
<a name="l00691"></a>00691         entryIndexOfNextEntry = _rangeEntries.length;
<a name="l00692"></a>00692 
<a name="l00693"></a>00693     _string = _string.substring(0, anIndex) + aString._string + _string.substring(anIndex);
<a name="l00694"></a>00694 
<a name="l00695"></a>00695     var current = entryIndexOfNextEntry;
<a name="l00696"></a>00696     <span class="keywordflow">while</span> (current &lt; _rangeEntries.length)
<a name="l00697"></a>00697         _rangeEntries[current++].range.location += length;
<a name="l00698"></a>00698 
<a name="l00699"></a>00699     var newRangeEntryCount = otherRangeEntries.length,
<a name="l00700"></a>00700         index = 0;
<a name="l00701"></a>00701 
<a name="l00702"></a>00702     <span class="keywordflow">while</span> (index &lt; newRangeEntryCount)
<a name="l00703"></a>00703     {
<a name="l00704"></a>00704         var entryCopy = copyRangeEntry(otherRangeEntries[index++]);
<a name="l00705"></a>00705         entryCopy.range.location += anIndex;
<a name="l00706"></a>00706         
<a name="l00707"></a>00707         _rangeEntries.splice(entryIndexOfNextEntry-1+index, 0, entryCopy);
<a name="l00708"></a>00708     }
<a name="l00709"></a>00709 
<a name="l00710"></a>00710     <span class="comment">//necessary?</span>
<a name="l00711"></a>00711     <span class="comment">//[self _coalesceRangeEntriesFromIndex:startingEntryIndex toIndex:startingEntryIndex+rangeEntries.length];</span>
<a name="l00712"></a>00712 
<a name="l00713"></a>00713     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a78a167606f00439f78f1fa5b2f384935">endEditing</a>];
<a name="l00714"></a>00714 }
<a name="l00715"></a>00715 
<a name="l00724"></a><a class="code" href="class_c_p_attributed_string.html#ad59532d86720f222abdf18ed5c92f58c">00724</a> - (void)replaceCharactersInRange:(CPRange)aRange withAttributedString:(<a class="code" href="class_c_p_attributed_string.html" title="A mutable character string with attributes.">CPAttributedString</a>)aString
<a name="l00725"></a>00725 {
<a name="l00726"></a>00726     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#af03c792e2666774116d7030ee43df31b">beginEditing</a>];
<a name="l00727"></a>00727         
<a name="l00728"></a>00728     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#abd8d8d8b5051572a07dbbfbdccf02e3f">deleteCharactersInRange</a>:aRange];
<a name="l00729"></a>00729     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a5b8893f059d055cacf2953344155315b">insertAttributedString</a>:aString <a class="code" href="class_c_p_attributed_string.html#a5b8893f059d055cacf2953344155315b">atIndex</a>:aRange.location];
<a name="l00730"></a>00730     
<a name="l00731"></a>00731     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a78a167606f00439f78f1fa5b2f384935">endEditing</a>];
<a name="l00732"></a>00732 }
<a name="l00733"></a>00733 
<a name="l00739"></a><a class="code" href="class_c_p_attributed_string.html#a132b3d0ea39601892cacb7170849ba6c">00739</a> - (void)setAttributedString:(<a class="code" href="class_c_p_attributed_string.html" title="A mutable character string with attributes.">CPAttributedString</a>)aString
<a name="l00740"></a>00740 {
<a name="l00741"></a>00741     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#af03c792e2666774116d7030ee43df31b">beginEditing</a>];
<a name="l00742"></a>00742     
<a name="l00743"></a>00743     _string = aString._string;
<a name="l00744"></a>00744     _rangeEntries = [];
<a name="l00745"></a>00745     
<a name="l00746"></a>00746     <span class="keywordflow">for</span> (var i=0, count = aString._rangeEntries.<a class="code" href="class_c_p_attributed_string.html#a739ed5cfe475ebd1d02d072b901191b5">length</a>; i&lt;count; i++)
<a name="l00747"></a>00747         _rangeEntries.push(copyRangeEntry(aString._rangeEntries[i]));
<a name="l00748"></a>00748 
<a name="l00749"></a>00749     [<span class="keyword">self</span> <a class="code" href="class_c_p_attributed_string.html#a78a167606f00439f78f1fa5b2f384935">endEditing</a>];
<a name="l00750"></a>00750 }
<a name="l00751"></a>00751 
<a name="l00752"></a>00752 <span class="comment">//Private methods</span>
<a name="l00753"></a>00753 - (Number)_indexOfRangeEntryForIndex:(<span class="keywordtype">unsigned</span>)characterIndex splitOnMaxIndex:(BOOL)split
<a name="l00754"></a>00754 {
<a name="l00755"></a>00755     var index = [<span class="keyword">self</span> _indexOfEntryWithIndex:characterIndex];
<a name="l00756"></a>00756     
<a name="l00757"></a>00757     <span class="keywordflow">if</span> (index &lt; 0)
<a name="l00758"></a>00758         <span class="keywordflow">return</span> index;
<a name="l00759"></a>00759 
<a name="l00760"></a>00760     var rangeEntry = _rangeEntries[index];
<a name="l00761"></a>00761     
<a name="l00762"></a>00762     <span class="keywordflow">if</span> (rangeEntry.range.location == characterIndex || (<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(rangeEntry.range) - 1 == characterIndex &amp;&amp; !split))
<a name="l00763"></a>00763         <span class="keywordflow">return</span> index;
<a name="l00764"></a>00764         
<a name="l00765"></a>00765     var newEntries = splitRangeEntryAtIndex(rangeEntry, characterIndex);
<a name="l00766"></a>00766     _rangeEntries.splice(index, 1, newEntries[0], newEntries[1]);
<a name="l00767"></a>00767     index++;
<a name="l00768"></a>00768 
<a name="l00769"></a>00769     <span class="keywordflow">return</span> index;
<a name="l00770"></a>00770 }
<a name="l00771"></a>00771 
<a name="l00772"></a>00772 - (void)_coalesceRangeEntriesFromIndex:(<span class="keywordtype">unsigned</span>)start toIndex:(<span class="keywordtype">unsigned</span>)end
<a name="l00773"></a>00773 {
<a name="l00774"></a>00774     var current = start;
<a name="l00775"></a>00775 
<a name="l00776"></a>00776     <span class="keywordflow">if</span> (end &gt;= _rangeEntries.length)
<a name="l00777"></a>00777         end = _rangeEntries.length -1;
<a name="l00778"></a>00778 
<a name="l00779"></a>00779     <span class="keywordflow">while</span> (current &lt; end)
<a name="l00780"></a>00780     {
<a name="l00781"></a>00781         var a = _rangeEntries[current],
<a name="l00782"></a>00782             b = _rangeEntries[current+1];
<a name="l00783"></a>00783 
<a name="l00784"></a>00784         <span class="keywordflow">if</span> ([a.attributes isEqualToDictionary:b.attributes])
<a name="l00785"></a>00785         {
<a name="l00786"></a>00786             a.range.length = <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(b.range) - a.range.location;
<a name="l00787"></a>00787             _rangeEntries.splice(current+1, 1);
<a name="l00788"></a>00788             end--;
<a name="l00789"></a>00789         }
<a name="l00790"></a>00790         <span class="keywordflow">else</span>
<a name="l00791"></a>00791             current++;
<a name="l00792"></a>00792     }
<a name="l00793"></a>00793 }
<a name="l00794"></a>00794 
<a name="l00795"></a>00795 <span class="comment">//Grouping Changes</span>
<a name="l00800"></a><a class="code" href="class_c_p_attributed_string.html#af03c792e2666774116d7030ee43df31b">00800</a> <span class="comment"></span>- (void)beginEditing
<a name="l00801"></a>00801 {
<a name="l00802"></a>00802     <span class="comment">//do nothing (says cocotron and gnustep)</span>
<a name="l00803"></a>00803 }
<a name="l00804"></a>00804 
<a name="l00809"></a><a class="code" href="class_c_p_attributed_string.html#a78a167606f00439f78f1fa5b2f384935">00809</a> - (void)endEditing
<a name="l00810"></a>00810 {
<a name="l00811"></a>00811     <span class="comment">//do nothing (says cocotron and gnustep)</span>
<a name="l00812"></a>00812 }
<a name="l00813"></a>00813 
<a name="l00814"></a>00814 <span class="keyword">@end</span>
<a name="l00815"></a>00815 
<a name="l00824"></a><a class="code" href="class_c_p_mutable_attributed_string.html">00824</a> <span class="keyword">@implementation </span><a class="code" href="class_c_p_mutable_attributed_string.html">CPMutableAttributedString</a> : <a class="code" href="class_c_p_attributed_string.html" title="A mutable character string with attributes.">CPAttributedString</a> {}
<a name="l00825"></a>00825 <span class="keyword">@end</span>
<a name="l00826"></a>00826 
<a name="l00827"></a>00827 var isEqual = function isEqual(a, b)
<a name="l00828"></a>00828 {
<a name="l00829"></a>00829     <span class="keywordflow">if</span> (a == b)
<a name="l00830"></a>00830         <span class="keywordflow">return</span> YES;
<a name="l00831"></a>00831 
<a name="l00832"></a>00832     <span class="keywordflow">if</span> ([a respondsToSelector:<span class="keyword">@selector</span>(isEqual:)] &amp;&amp; [a isEqual:b])
<a name="l00833"></a>00833         <span class="keywordflow">return</span> YES;
<a name="l00834"></a>00834 
<a name="l00835"></a>00835     <span class="keywordflow">return</span> NO;
<a name="l00836"></a>00836 }
<a name="l00837"></a>00837 
<a name="l00838"></a>00838 var makeRangeEntry = function makeRangeEntry(<span class="comment">/*CPRange*/</span>aRange, <span class="comment">/*CPDictionary*/</span>attributes)
<a name="l00839"></a>00839 {
<a name="l00840"></a>00840     <span class="keywordflow">return</span> {range:aRange, attributes:[attributes <a class="code" href="class_c_p_dictionary.html#a735a2d2daeff5890c6246aafe9f3edff">copy</a>]};
<a name="l00841"></a>00841 }
<a name="l00842"></a>00842 
<a name="l00843"></a>00843 var copyRangeEntry = function copyRangeEntry(<span class="comment">/*RangeEntry*/</span>aRangeEntry)
<a name="l00844"></a>00844 {
<a name="l00845"></a>00845     <span class="keywordflow">return</span> makeRangeEntry(<a class="code" href="group__foundation.html#gae4d4352191524cc80edd4fb130b1495b">CPCopyRange</a>(aRangeEntry.range), [aRangeEntry.attributes copy]);
<a name="l00846"></a>00846 }
<a name="l00847"></a>00847 
<a name="l00848"></a>00848 var splitRangeEntry = function splitRangeEntryAtIndex(<span class="comment">/*RangeEntry*/</span>aRangeEntry, <span class="comment">/*unsigned*/</span>anIndex)
<a name="l00849"></a>00849 {
<a name="l00850"></a>00850     var newRangeEntry = copyRangeEntry(aRangeEntry),
<a name="l00851"></a>00851         cachedIndex = <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(aRangeEntry.range);
<a name="l00852"></a>00852     
<a name="l00853"></a>00853     aRangeEntry.range.length = anIndex - aRangeEntry.range.location;
<a name="l00854"></a>00854     newRangeEntry.range.location = anIndex;
<a name="l00855"></a>00855     newRangeEntry.range.length = cachedIndex - anIndex;
<a name="l00856"></a>00856     newRangeEntry.attributes = [newRangeEntry.attributes copy];
<a name="l00857"></a>00857     
<a name="l00858"></a>00858     <span class="keywordflow">return</span> [aRangeEntry, newRangeEntry];
<a name="l00859"></a>00859 }
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Apr 6 10:32:56 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_attributed_string_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:29 GMT -->
</html>