Changeset 634 for trunk/ab5.0
- Timestamp:
- Sep 26, 2008, 8:47:44 PM (16 years ago)
- Location:
- trunk/ab5.0/ablib/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/System/Object.ab
r449 r634 13 13 ' 2つのオブジェクトが等しいかどうかを判断する 14 14 Virtual Function Equals( object As Object ) As Boolean 15 If ObjPtr(This) = ObjPtr(object) Then 16 ' If This.GetHashCode() = object.GetHashCode() Then 17 Return True 18 Else 19 Return False 20 End If 15 Return ObjPtr(This) = ObjPtr(object) 21 16 End Function 22 17 23 18 Static Function Equals( objectA As Object, objectB As Object ) As Boolean 24 If ObjPtr(objectA) = NULL /*objectA = Nothing*/Then25 Return ObjPtr(objectB) = NULL 'objectB = Nothing19 If ActiveBasic.IsNothing(objectA) Then 20 Return ActiveBasic.IsNothing(objectB) 26 21 Else 27 22 Return objectA.Equals(objectB) -
trunk/ab5.0/ablib/src/Classes/System/String.ab
r621 r634 128 128 129 129 Const Function Operator == (y As String) As Boolean 130 Return Compare (This, y) = 0130 Return CompareOrdinal(This, y) = 0 131 131 End Function 132 132 133 133 Const Function Operator == (y As *Char) As Boolean 134 Return Compare (This, y) = 0134 Return CompareOrdinal(This, y) = 0 135 135 End Function 136 136 137 137 Const Function Operator <> (y As String) As Boolean 138 Return Compare (This, y) <> 0138 Return CompareOrdinal(This, y) <> 0 139 139 End Function 140 140 141 141 Const Function Operator <> (y As *Char) As Boolean 142 Return Compare (This, y) <> 0142 Return CompareOrdinal(This, y) <> 0 143 143 End Function 144 144 145 145 Const Function Operator < (y As String) As Boolean 146 Return Compare (This, y) < 0146 Return CompareOrdinal(This, y) < 0 147 147 End Function 148 148 149 149 Const Function Operator < (y As *Char) As Boolean 150 Return Compare (This, y) < 0150 Return CompareOrdinal(This, y) < 0 151 151 End Function 152 152 153 153 Const Function Operator > (y As String) As Boolean 154 Return Compare (This, y) > 0154 Return CompareOrdinal(This, y) > 0 155 155 End Function 156 156 157 157 Const Function Operator > (y As *Char) As Boolean 158 Return Compare (This, y) > 0158 Return CompareOrdinal(This, y) > 0 159 159 End Function 160 160 161 161 Const Function Operator <= (y As String) As Boolean 162 Return Compare (This, y) <= 0162 Return CompareOrdinal(This, y) <= 0 163 163 End Function 164 164 165 165 Const Function Operator <= (y As *Char) As Boolean 166 Return Compare (This, y) <= 0166 Return CompareOrdinal(This, y) <= 0 167 167 End Function 168 168 169 169 Const Function Operator >= (y As String) As Boolean 170 Return Compare (This, y) >= 0170 Return CompareOrdinal(This, y) >= 0 171 171 End Function 172 172 173 173 Const Function Operator >= (y As *Char) As Boolean 174 Return Compare(This, y) >= 0 175 End Function 176 174 Return CompareOrdinal(This, y) >= 0 175 End Function 176 177 /*! 178 @brief 単語順での文字列比較 179 @auther Egtra 180 */ 177 181 Static Function Compare(x As String, y As String) As Long 178 Return CompareOrdinal(x, y) 179 End Function 180 181 Public 182 'Compareなどで、x.Charsではなく、StrPtr(x)と書く理由は、xがNothingの場合のため。 182 Return Compare(x, y, False) 183 End Function 184 185 Static Function Compare(x As String, y As String, ignoreCase As Boolean) As Long 186 Dim lhs = removeNull(x) 187 Dim rhs = removeNull(y) 188 Return compareImpl(lhs.Chars, lhs.Length, rhs.Chars, rhs.Length, ignoreCase) 189 End Function 183 190 184 191 Static Function Compare(x As String, indexX As Long, y As String, indexY As Long, length As Long) As Long 185 Return CompareOrdinal(x, indexX, y, indexY, length) 186 End Function 187 192 Return Compare(x, indexX, y, indexY, length, False) 193 End Function 194 195 Static Function Compare(x As String, indexX As Long, y As String, indexY As Long, length As Long, ignoreCase As Boolean) As Long 196 Dim lhs = removeNull(x) 197 Dim rhs = removeNull(y) 198 If lhs.Length > indexX Or indexX < 0 Then 199 Throw New ArgumentOutOfRangeException("indexX") 200 ElseIf rhs.Length > indexY Or indexY < 0 Then 201 Throw New ArgumentOutOfRangeException("indexY") 202 ElseIf length < 0 Then 203 Throw New ArgumentOutOfRangeException("length") 204 End If 205 Dim cmpLen = Math.Min(Math.Min(lhs.Length - indexX, rhs.Length - indexY), length) 206 Return compareImpl(VarPtr(lhs.Chars[indexX]), cmpLen, VarPtr(rhs.Chars[indexY]), cmpLen, ignoreCase) 207 End Function 208 209 /*! 210 @brief 序数での文字列比較 211 */ 188 212 Static Function CompareOrdinal(x As String, y As String) As Long 189 Return CompareOrdinal(StrPtr(x), StrPtr(y)) 213 Dim lhs = removeNull(x) 214 Dim rhs = removeNull(y) 215 Return compareOrdinalImpl(lhs.Chars, lhs.Length, rhs.Chars, rhs.Length) 190 216 End Function 191 217 192 218 Static Function CompareOrdinal(x As String, indexX As Long, y As String, indexY As Long, length As Long) As Long 193 Return CompareOrdinal(StrPtr(x), indexX, StrPtr(y), indexY, length) 194 End Function 219 Dim lhs = removeNull(x) 220 Dim rhs = removeNull(y) 221 If lhs.Length > indexX Or indexX < 0 Then 222 Throw New ArgumentOutOfRangeException("indexX") 223 ElseIf rhs.Length > indexY Or indexY < 0 Then 224 Throw New ArgumentOutOfRangeException("indexY") 225 ElseIf length < 0 Then 226 Throw New ArgumentOutOfRangeException("length") 227 End If 228 Dim cmpLen = Math.Min(Math.Min(lhs.Length - indexX, rhs.Length - indexY), length) 229 Return compareOrdinalImpl(VarPtr(lhs.Chars[indexX]), cmpLen, VarPtr(rhs.Chars[indexY]), cmpLen) 230 End Function 231 232 Static Function CompareOrdinal(x As String, y As *Char) As Long 233 Dim lhs = removeNull(x) 234 Return compareOrdinalImpl(lhs.Chars, lhs.Length, y, lstrlen(y)) 235 End Function 236 195 237 Private 196 Static Function Compare(x As String, y As *Char) As Long 197 Return CompareOrdinal(x, y) 198 End Function 199 200 Static Function CompareOrdinal(x As String, y As *Char) As Long 201 Return CompareOrdinal(StrPtr(x), y) 202 End Function 203 204 Static Function CompareOrdinal(x As *Char, y As *Char) As Long 205 If x = 0 Then 206 If y = 0 Then 207 Return 0 208 Else 209 Return -1 210 End If 211 ElseIf y = 0 Then 212 Return 1 213 End If 214 Return ActiveBasic.Strings.StrCmp(x, y) 215 End Function 216 217 Static Function CompareOrdinal(x As *Char, indexX As Long, y As *Char, indexY As Long, length As Long) As Long 218 If x = 0 Then 219 If y = 0 Then 220 Return 0 221 Else 222 Return -1 223 End If 224 ElseIf y = 0 Then 225 Return 1 226 End If 227 Return ActiveBasic.Strings.ChrCmp(VarPtr(x[indexX]), VarPtr(y[indexY]), length As SIZE_T) 228 End Function 238 Static Function compareImpl(x As *Char, lenX As Long, y As *Char, lenY As Long, ignoreCase As Boolean) As Long 239 Dim flags = 0 As DWord 240 If ignoreCase Then 241 flags = NORM_IGNORECASE 242 End If 243 Dim ret = CompareString(LOCALE_USER_DEFAULT, ignoreCase, x, lenX, y, lenY) 244 Select Case ret 245 Case CSTR_LESS_THAN 246 compareImpl = -1 247 Case CSTR_EQUAL 248 compareImpl = 0 249 Case CSTR_GREATER_THAN 250 compareImpl = 1 251 Case Else 252 ActiveBasic.Windows.ThrowWithLastError("String.Compare") 253 End Select 254 End Function 255 256 Static Function compareOrdinalImpl(x As *Char, lenX As Long, y As *Char, lenY As Long) As Long 257 Return ActiveBasic.Strings.ChrCmp(x, lenX As SIZE_T, y, lenY As SIZE_T) 258 End Function 259 229 260 Public 230 261 Function CompareTo(y As String) As Long -
trunk/ab5.0/ablib/src/basic/function.sbp
r628 r634 323 323 Function Right$(s As String, length As Long) As String 324 324 If Not ActiveBasic.IsNothing(s) Then 325 Right$ = s.Substring(System.Math.Max(0, s.Length - length) , s.Length)325 Right$ = s.Substring(System.Math.Max(0, s.Length - length)) 326 326 Else 327 327 Right$ = ""
Note:
See TracChangeset
for help on using the changeset viewer.