Mercurial > projects > dwt-mac
annotate dwt/internal/cocoa/NSString.d @ 139:86fc761a24ae
Fixes #11
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 04 Jun 2009 23:23:10 +0200 |
parents | 3d9eb62cd2e3 |
children | e91dcbf77cc7 |
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() { | |
138 | 39 wchar[] buffer = new wchar[lengthOfCharacters]; |
45 | 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 |
139 | 44 public wchar[] getString16() { |
45 wchar[] buffer = new wchar[lengthOfCharacters]; | |
46 getCharacters(buffer.ptr); | |
47 return buffer; | |
48 } | |
49 | |
45 | 50 public static NSString stringWith(String str) { |
137 | 51 return stringWithUTF8String((str ~ '\0').ptr); |
45 | 52 } |
53 | |
139 | 54 public static NSString stringWith16(wchar[] buffer) { |
55 return stringWithCharacters(buffer.ptr, buffer.length); | |
56 } | |
57 | |
45 | 58 public /*const*/char* UTF8String() { |
59 return cast(/*const*/char*) OS.objc_msgSend(this.id, OS.sel_UTF8String); | |
60 } | |
61 | |
62 public wchar characterAtIndex(NSUInteger index) { | |
63 return cast(wchar) OS.objc_msgSend(this.id, OS.sel_characterAtIndex_, index); | |
64 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
65 |
45 | 66 public void getCharacters(wchar* buffer) { |
67 OS.objc_msgSend(this.id, OS.sel_getCharacters_, buffer); | |
68 } | |
69 | |
70 public void getCharacters(wchar* buffer, NSRange aRange) { | |
71 OS.objc_msgSend(this.id, OS.sel_getCharacters_range_, buffer, aRange); | |
72 } | |
73 | |
74 public bool isEqualToString(NSString aString) { | |
75 return OS.objc_msgSend_bool(this.id, OS.sel_isEqualToString_, aString !is null ? aString.id : null); | |
76 } | |
77 | |
78 public NSString lastPathComponent() { | |
79 objc.id result = OS.objc_msgSend(this.id, OS.sel_lastPathComponent); | |
80 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
|
81 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
82 |
45 | 83 public NSUInteger length() { |
84 return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_length); | |
85 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
86 |
138 | 87 public NSUInteger lengthOfCharacters() { |
88 return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_length); | |
89 } | |
90 | |
91 public NSUInteger lengthOfBytesUsingEncoding(NSStringEncoding enc) { | |
92 return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_lengthOfBytesUsingEncoding_, enc); | |
93 } | |
94 | |
45 | 95 public NSString lowercaseString() { |
96 objc.id result = OS.objc_msgSend(this.id, OS.sel_lowercaseString); | |
97 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
98 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
99 |
45 | 100 public NSString stringByAddingPercentEscapesUsingEncoding(NSStringEncoding enc) { |
101 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByAddingPercentEscapesUsingEncoding_, enc); | |
102 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
103 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
104 |
45 | 105 public NSString stringByAppendingPathComponent(NSString str) { |
106 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByAppendingPathComponent_, str !is null ? str.id : null); | |
107 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
108 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
109 |
45 | 110 public NSString stringByAppendingString(NSString aString) { |
111 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByAppendingString_, aString !is null ? aString.id : null); | |
112 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
113 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
114 |
45 | 115 public NSString stringByDeletingLastPathComponent() { |
116 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByDeletingLastPathComponent); | |
117 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
118 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
119 |
45 | 120 public NSString stringByDeletingPathExtension() { |
121 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByDeletingPathExtension); | |
122 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
123 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
124 |
45 | 125 public NSString stringByReplacingOccurrencesOfString(NSString target, NSString replacement) { |
126 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByReplacingOccurrencesOfString_withString_, target !is null ? target.id : null, replacement !is null ? replacement.id : null); | |
127 return result is this.id ? this : (result !is null ? new NSString(result) : null); | |
128 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
129 |
45 | 130 public static NSString stringWithCharacters(/*const*/wchar* characters, NSUInteger length) { |
131 objc.id result = OS.objc_msgSend(OS.class_NSString, OS.sel_stringWithCharacters_length_, characters, length); | |
132 return result !is null ? new NSString(result) : null; | |
133 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
134 |
45 | 135 public static NSString stringWithUTF8String(/*const*/char* nullTerminatedCString) { |
136 objc.id result = OS.objc_msgSend(OS.class_NSString, OS.sel_stringWithUTF8String_, nullTerminatedCString); | |
137 return result !is null ? new NSString(result) : null; | |
138 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
139 |
138 | 140 } |