|
35 | 35 | } |
36 | 36 | } |
37 | 37 |
|
| 38 | + public convenience init(describing subject: Object) { |
| 39 | + /*if let instance = subject as? ITextOutputStreamable { |
| 40 | + instance.write(to: ) |
| 41 | + } else*/ if let instance = subject as? ICustomStringConvertible { |
| 42 | + return instance.description |
| 43 | + } else if let instance = subject as? CustomDebugStringConvertible { |
| 44 | + return instance.debugDescription |
| 45 | + } else { |
| 46 | + return init(subject) |
| 47 | + } |
| 48 | + } |
| 49 | + |
38 | 50 | public convenience init(reflecting subject: Object) { |
39 | 51 | if let o = subject as? ICustomDebugStringConvertible { |
40 | 52 | return o.debugDescription |
| 53 | + } else if let instance = subject as? ICustomStringConvertible { |
| 54 | + return instance.description |
| 55 | + //} else if let instance = subject as? ITextOutputStreamable { |
| 56 | + //instance.write(to: ) |
41 | 57 | } else { |
42 | 58 | #if JAVA |
43 | 59 | // ToDo: fall back to reflection to call debugDescription? |
|
112 | 128 | return 0 |
113 | 129 | } |
114 | 130 |
|
| 131 | + //public var capitalized: NativeString { |
| 132 | + ////return uppercaseString |
| 133 | + //} |
| 134 | + |
| 135 | + //func components(separatedBy separator: CharacterSet) -> [String] { |
| 136 | + //} |
| 137 | + |
| 138 | + func components(separatedBy separator: String) -> [String] { |
| 139 | + let separatorLength = separator.length() |
| 140 | + if separatorLength == 0 { |
| 141 | + return [self] |
| 142 | + } |
| 143 | + |
| 144 | + #if COOPER |
| 145 | + //exit nativeString.split(java.util.regex.Pattern.quote(Separator)) as not nullable |
| 146 | + //Custom implementation because `mapped.split` strips empty parts at the end, making it incompatible with the other three platfroms. |
| 147 | + var result = [String]() |
| 148 | + var i = 0 |
| 149 | + while true { |
| 150 | + let p = indexOf(separator, i) |
| 151 | + if p > -1 { |
| 152 | + let part = substring(i, p-i) |
| 153 | + result.append(part) |
| 154 | + i = p+separatorLength |
| 155 | + } else { |
| 156 | + let part = substring(i) |
| 157 | + result.append(part) |
| 158 | + break |
| 159 | + } |
| 160 | + } |
| 161 | + return result |
| 162 | + #elseif ECHOES |
| 163 | + return [String](Split([separator], StringSplitOptions.None).ToList()) |
| 164 | + #elseif ISLAND |
| 165 | + return [String](Split(separator).ToList()) |
| 166 | + #elseif TOFFEE |
| 167 | + return [String](componentsSeparatedByString(separator)) |
| 168 | + #endif |
| 169 | + } |
| 170 | + |
115 | 171 | #if !COCOA |
116 | 172 | public var uppercaseString: NativeString { |
117 | 173 | #if JAVA |
|
0 commit comments