Mercurial > projects > dwt-mac
annotate dwt/internal/cocoa/NSString.d @ 137:52d360200ae4
Fixed #7
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 30 May 2009 23:40:34 +0200 |
parents | 2e671fa40eec |
children | 3d9eb62cd2e3 |
rev | line source |
---|---|
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1 /******************************************************************************* |
45 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
7 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
8 * Contributors: |
45 | 9 * IBM Corporation - initial API and implementation |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
10 * |
13
f565d3a95c0a
Ported dwt.internal
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
1
diff
changeset
|
11 * Port to the D programming language: |
45 | 12 * Jacob Carlborg <doob@me.com> |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
13 *******************************************************************************/ |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
14 module dwt.internal.cocoa.NSString; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
15 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
16 import dwt.dwthelper.utils; |
45 | 17 import cocoa = dwt.internal.cocoa.id; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
18 import dwt.internal.cocoa.NSObject; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
19 import dwt.internal.cocoa.NSRange; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
20 import dwt.internal.cocoa.OS; |
45 | 21 import dwt.internal.objc.cocoa.Cocoa; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
22 import objc = dwt.internal.objc.runtime; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
23 |
45 | 24 public class NSString : NSObject { |
25 | |
26 public this() { | |
27 super(); | |
28 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
29 |
45 | 30 public this(objc.id id) { |
31 super(id); | |
32 } | |
33 | |
34 public this(cocoa.id id) { | |
35 super(id); | |
36 } | |
37 | |
38 public String getString() { | |
39 wchar[] buffer = new wchar[length()]; | |
40 getCharacters(buffer.ptr); | |
137 | 41 return dwt.dwthelper.utils.toString(buffer); |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
42 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
43 |
45 | 44 public static NSString stringWith(String str) { |
137 | 45 return stringWithUTF8String((str ~ '\0').ptr); |
45 | 46 } |
47 | |
48 public /*const*/char* UTF8String() { | |
49 return cast(/*const*/char*) OS.objc_msgSend(this.id, OS.sel_UTF8String); | |
50 } | |
51 | |
52 public wchar characterAtIndex(NSUInteger index) { | |
53 return cast(wchar) OS.objc_msgSend(this.id, OS.sel_characterAtIndex_, index); | |
54 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
55 |
45 | 56 public void getCharacters(wchar* buffer) { |
57 OS.objc_msgSend(this.id, OS.sel_getCharacters_, buffer); | |
58 } | |
59 | |
60 public void getCharacters(wchar* buffer, NSRange aRange) { | |
61 OS.objc_msgSend(this.id, OS.sel_getCharacters_range_, buffer, aRange); | |
62 } | |
63 | |
64 public bool isEqualToString(NSString aString) { | |
65 return OS.objc_msgSend_bool(this.id, OS.sel_isEqualToString_, aString !is null ? aString.id : null); | |
66 } | |
67 | |
68 public NSString lastPathComponent() { | |
69 objc.id result = OS.objc_msgSend(this.id, OS.sel_lastPathComponent); | |
70 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
71 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
72 |
45 | 73 public NSUInteger length() { |
74 return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_length); | |
75 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
76 |
45 | 77 public NSString lowercaseString() { |
78 objc.id result = OS.objc_msgSend(this.id, OS.sel_lowercaseString); | |
79 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
80 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
81 |
45 | 82 public NSString stringByAddingPercentEscapesUsingEncoding(NSStringEncoding enc) { |
83 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByAddingPercentEscapesUsingEncoding_, enc); | |
84 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
85 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
86 |
45 | 87 public NSString stringByAppendingPathComponent(NSString str) { |
88 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByAppendingPathComponent_, str !is null ? str.id : null); | |
89 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
90 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
91 |
45 | 92 public NSString stringByAppendingString(NSString aString) { |
93 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByAppendingString_, aString !is null ? aString.id : null); | |
94 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
95 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
96 |
45 | 97 public NSString stringByDeletingLastPathComponent() { |
98 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByDeletingLastPathComponent); | |
99 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
100 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
101 |
45 | 102 public NSString stringByDeletingPathExtension() { |
103 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByDeletingPathExtension); | |
104 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
105 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
106 |
45 | 107 public NSString stringByReplacingOccurrencesOfString(NSString target, NSString replacement) { |
108 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByReplacingOccurrencesOfString_withString_, target !is null ? target.id : null, replacement !is null ? replacement.id : null); | |
109 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
110 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
111 |
45 | 112 public static NSString stringWithCharacters(/*const*/wchar* characters, NSUInteger length) { |
113 objc.id result = OS.objc_msgSend(OS.class_NSString, OS.sel_stringWithCharacters_length_, characters, length); | |
114 return result !is null ? new NSString(result) : null; | |
115 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
116 |
45 | 117 public static NSString stringWithUTF8String(/*const*/char* nullTerminatedCString) { |
118 objc.id result = OS.objc_msgSend(OS.class_NSString, OS.sel_stringWithUTF8String_, nullTerminatedCString); | |
119 return result !is null ? new NSString(result) : null; | |
120 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
121 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
122 } |