Mercurial > projects > dwt-mac
annotate dwt/internal/cocoa/NSString.d @ 138:3d9eb62cd2e3
Fixes #8
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 03 Jun 2009 00:36:31 +0200 |
parents | 52d360200ae4 |
children | 86fc761a24ae |
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 |
138 | 24 import tango.stdc.stdlib; |
25 | |
45 | 26 public class NSString : NSObject { |
27 | |
28 public this() { | |
29 super(); | |
30 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
31 |
45 | 32 public this(objc.id id) { |
33 super(id); | |
34 } | |
35 | |
36 public this(cocoa.id id) { | |
37 super(id); | |
38 } | |
39 | |
40 public String getString() { | |
138 | 41 wchar[] buffer = new wchar[lengthOfCharacters]; |
45 | 42 getCharacters(buffer.ptr); |
137 | 43 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
|
44 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
45 |
45 | 46 public static NSString stringWith(String str) { |
137 | 47 return stringWithUTF8String((str ~ '\0').ptr); |
45 | 48 } |
49 | |
50 public /*const*/char* UTF8String() { | |
51 return cast(/*const*/char*) OS.objc_msgSend(this.id, OS.sel_UTF8String); | |
52 } | |
53 | |
54 public wchar characterAtIndex(NSUInteger index) { | |
55 return cast(wchar) OS.objc_msgSend(this.id, OS.sel_characterAtIndex_, index); | |
56 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
57 |
45 | 58 public void getCharacters(wchar* buffer) { |
59 OS.objc_msgSend(this.id, OS.sel_getCharacters_, buffer); | |
60 } | |
61 | |
62 public void getCharacters(wchar* buffer, NSRange aRange) { | |
63 OS.objc_msgSend(this.id, OS.sel_getCharacters_range_, buffer, aRange); | |
64 } | |
65 | |
66 public bool isEqualToString(NSString aString) { | |
67 return OS.objc_msgSend_bool(this.id, OS.sel_isEqualToString_, aString !is null ? aString.id : null); | |
68 } | |
69 | |
70 public NSString lastPathComponent() { | |
71 objc.id result = OS.objc_msgSend(this.id, OS.sel_lastPathComponent); | |
72 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
|
73 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
74 |
45 | 75 public NSUInteger length() { |
76 return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_length); | |
77 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
78 |
138 | 79 public NSUInteger lengthOfCharacters() { |
80 return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_length); | |
81 } | |
82 | |
83 public NSUInteger lengthOfBytesUsingEncoding(NSStringEncoding enc) { | |
84 return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_lengthOfBytesUsingEncoding_, enc); | |
85 } | |
86 | |
45 | 87 public NSString lowercaseString() { |
88 objc.id result = OS.objc_msgSend(this.id, OS.sel_lowercaseString); | |
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 stringByAddingPercentEscapesUsingEncoding(NSStringEncoding enc) { |
93 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByAddingPercentEscapesUsingEncoding_, enc); | |
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 stringByAppendingPathComponent(NSString str) { |
98 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByAppendingPathComponent_, str !is null ? str.id : null); | |
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 stringByAppendingString(NSString aString) { |
103 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByAppendingString_, aString !is null ? aString.id : null); | |
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 stringByDeletingLastPathComponent() { |
108 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByDeletingLastPathComponent); | |
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 NSString stringByDeletingPathExtension() { |
113 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByDeletingPathExtension); | |
114 return result is this.id ? this : (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 NSString stringByReplacingOccurrencesOfString(NSString target, NSString replacement) { |
118 objc.id result = OS.objc_msgSend(this.id, OS.sel_stringByReplacingOccurrencesOfString_withString_, target !is null ? target.id : null, replacement !is null ? replacement.id : null); | |
119 return result is this.id ? this : (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 |
45 | 122 public static NSString stringWithCharacters(/*const*/wchar* characters, NSUInteger length) { |
123 objc.id result = OS.objc_msgSend(OS.class_NSString, OS.sel_stringWithCharacters_length_, characters, length); | |
124 return result !is null ? new NSString(result) : null; | |
125 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
126 |
45 | 127 public static NSString stringWithUTF8String(/*const*/char* nullTerminatedCString) { |
128 objc.id result = OS.objc_msgSend(OS.class_NSString, OS.sel_stringWithUTF8String_, nullTerminatedCString); | |
129 return result !is null ? new NSString(result) : null; | |
130 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
131 |
138 | 132 } |