Develop and Download Open Source Software

Browse CVS Repository

Contents of /undmail/guiproto/TextFormatter.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Fri Feb 14 16:50:14 2003 UTC (21 years, 2 months ago) by footashida
Branch: MAIN
*** empty log message ***

1 #import "TextFormatter.h"
2
3
4 @implementation TextFormatter
5 -(NSDictionary *)attributedDictionary{
6 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
7 _foregroundColor, NSForegroundColorAttributeName,
8 _backgroundColor, NSBackgroundColorAttributeName,
9 _font, NSFontAttributeName,
10 nil];
11 return dict;
12 }
13
14
15 -(id)initWithName:(NSString *)name
16 pattern:(NSString *)pattern
17 foregroundColor:(NSColor *)foregroundColor
18 backgroundColor:(NSColor *)backgroundColor
19 font:(NSFont *)font{
20 self = [super init];
21 _name = [name retain];
22 _pattern = [pattern retain];
23 _foregroundColor = [foregroundColor retain];
24 _backgroundColor = [backgroundColor retain];
25 _font = [font retain];
26 return self;
27 }
28 -(void)dealloc{
29 [_name release];
30 [_pattern release];
31 [_foregroundColor release];
32 [_backgroundColor release];
33 [_font release];
34 [super dealloc];
35 }
36 -(NSString *)name{
37 return _name;
38 }
39 -(NSString *)pattern{
40 return _pattern;
41 }
42 -(NSColor *)foregroundColor{
43 return _foregroundColor;
44 }
45 -(NSColor *)backgroundColor{
46 return _backgroundColor;
47 }
48 -(NSFont *)font{
49 return _font;
50 }
51 -(NSAttributedString *)formatWithAttributedString:
52 (NSAttributedString *)attributedString{
53 NSString *string;
54 NSMutableAttributedString *ret;
55 NSRange patternRange;
56 NSRange stringRange;
57
58 ret = [[[NSMutableAttributedString alloc] init] autorelease];
59 [ret appendAttributedString:attributedString];
60
61 // pattern������������������������������������������������������
62 string = [attributedString string];
63 if([_pattern isEqual:@""]){
64 [ret setAttributes:[self attributedDictionary]
65 range:NSMakeRange(0, [string length])];
66 return ret;
67 }
68
69 stringRange = NSMakeRange(0, [string length]);
70 while(stringRange.length > 0){
71 patternRange = [string rangeOfString:_pattern
72 options:0
73 range:stringRange];
74 if(patternRange.location == NSNotFound){
75 return ret;
76 }
77 [ret setAttributes:[self attributedDictionary] range:patternRange];
78 stringRange.location = NSMaxRange(patternRange);
79 stringRange.length -= NSMaxRange(patternRange);
80 }
81 return ret;
82 }
83
84 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26