Changeset 132 for Include


Ignore:
Timestamp:
Mar 4, 2007, 11:28:44 PM (18 years ago)
Author:
イグトランス (egtra)
Message:

String型の自身を変更するメソッドを、戻り値で返すように変更。
併せて文字列比較を自前の関数で行うように変更。
プロンプトのキャレットの位置計算が正しくなかったバグを修正。

Location:
Include
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Include/Classes/System/String.ab

    r125 r132  
     1' Classes/System/String.ab
     2
     3#require <basic/function.sbp>
     4
    15Class String
    26    m_Length As Long
     
    5761    End Sub
    5862
    59     Const Function Operator[] (n As Long) As Char
     63    Const Function Operator [] (n As Long) As Char
    6064        Return Chars[n]
    6165    End Function
    6266
    63     Sub Operator[]= (n As Long, c As Char)
     67    Sub Operator []= (n As Long, c As Char)
    6468        Chars[n] = c
    6569    End Sub
    6670
    67     Const Function Operator + (lpszText As *Char) As String
    68         Return Concat(lpszText, lstrlen(lpszText))
     71    Const Function Operator + (pszText As *Char) As String
     72        Return Concat(pszText, lstrlen(pszText))
    6973    End Function
    7074
     
    7377    End Function
    7478
    75     Const Function Operator & (lpszText As *Char) As String
    76         Dim tempString = This + lpszText
     79    Const Function Operator & (pszText As *Char) As String
     80        Dim tempString = This + pszText
    7781        Return tempString
    7882    End Function
     
    8387    End Function
    8488
    85     Function Operator== (ByRef objString As String) As Long
    86         If lstrcmp(This, objString) = 0 Then
    87             Return _System_TRUE
    88         Else
    89             Return _System_FALSE
    90         End If
    91     End Function
    92 
    93     Function Operator== (lpszText As *Char) As Long
    94         If lstrcmp(This, lpszText) = 0 Then
    95             Return _System_TRUE
    96         Else
    97             Return _System_FALSE
    98         End If
    99     End Function
    100 
    101     Function Operator<> (ByRef objString As String) As Long
    102         Return lstrcmp(This, objString)
    103     End Function
    104 
    105     Function Operator<> (lpszText As *Char) As Long
    106         Return lstrcmp(This, lpszText)
    107     End Function
    108 
    109     Function Operator< (ByRef objString As String) As Long
    110         If lstrcmp(This, objString) < 0 Then
    111             Return _System_TRUE
    112         Else
    113             Return _System_FALSE
    114         End If
    115     End Function
    116 
    117     Function Operator< (lpszText As *Char) As Long
    118         If lstrcmp(This, lpszText) < 0 Then
    119             Return _System_TRUE
    120         Else
    121             Return _System_FALSE
    122         End If
    123     End Function
    124 
    125     Function Operator> (ByRef objString As String) As Long
    126         If lstrcmp(This, objString) > 0 Then
    127             Return _System_TRUE
    128         Else
    129             Return _System_FALSE
    130         End If
    131     End Function
    132 
    133     Function Operator> (lpszText As *Char) As Long
    134         If lstrcmp(This, lpszText) > 0 Then
    135             Return _System_TRUE
    136         Else
    137             Return _System_FALSE
    138         End If
    139     End Function
    140 
    141     Function Operator<= (ByRef objString As String) As Long
    142         If lstrcmp(This, objString) <= 0 Then
    143             Return _System_TRUE
    144         Else
    145             Return _System_FALSE
    146         End If
    147     End Function
    148 
    149     Function Operator<= (lpszText As *Char) As Long
    150         If lstrcmp(This, lpszText) <= 0 Then
    151             Return _System_TRUE
    152         Else
    153             Return _System_FALSE
    154         End If
    155     End Function
    156 
    157     Function Operator>= (ByRef objString As String) As Long
    158         If lstrcmp(This, objString) => 0 Then
    159             Return _System_TRUE
    160         Else
    161             Return _System_FALSE
    162         End If
    163     End Function
    164 
    165     Function Operator>= (lpszText As *Char) As Long
    166         If lstrcmp(This, lpszText) => 0 Then
    167             Return _System_TRUE
    168         Else
    169             Return _System_FALSE
    170         End If
    171     End Function
    172 
    173     Function StrPtr() As *Char
     89    Const Function Operator == (ByRef objString As String) As Boolean
     90        Return _System_StrCmp(This, objString) = 0
     91    End Function
     92
     93    Const Function Operator == (text As *Char) As Long
     94        Return _System_StrCmp(This, text) = 0
     95    End Function
     96
     97    Const Function Operator <> (ByRef objString As String) As Boolean
     98        Return _System_StrCmp(This, objString)
     99    End Function
     100
     101    Const Function Operator <> (text As *Char) As Boolean
     102        Return _System_StrCmp(This, text)
     103    End Function
     104
     105    Const Function Operator < (ByRef objString As String) As Boolean
     106        Return _System_StrCmp(This, objString) < 0
     107    End Function
     108
     109    Const Function Operator < (text As *Char) As Boolean
     110        Return _System_StrCmp(This, text) < 0
     111    End Function
     112
     113    Const Function Operator > (ByRef objString As String) As Boolean
     114        Return _System_StrCmp(This, objString) > 0
     115    End Function
     116
     117    Const Function Operator > (text As *Char) As Boolean
     118        Return _System_StrCmp(This, text) > 0
     119    End Function
     120
     121    Const Function Operator <= (ByRef objString As String) As Boolean
     122        Return _System_StrCmp(This, objString) <= 0
     123    End Function
     124
     125    Const Function Operator <= (text As *Char) As Boolean
     126        Return _System_StrCmp(This, text) <= 0
     127    End Function
     128
     129    Const Function Operator >= (ByRef objString As String) As Boolean
     130        Return _System_StrCmp(This, objString) => 0
     131    End Function
     132
     133    Const Function Operator >= (text As *Char) As Boolean
     134        Return _System_StrCmp(This, text) => 0
     135    End Function
     136
     137    Const Function StrPtr() As *Char
    174138        Return Chars
    175139    End Function
     
    248212    End Sub
    249213
    250     Function Concat(lpszText As *Char, textLength As Long) As String
     214    Const Function Clone() As String
     215        Return This
     216    End Function
     217
     218    Const Function Concat(lpszText As *Char, textLength As Long) As String
    251219        Dim tempString As String
    252220        With tempString
     
    259227    End Function
    260228
    261     Function Contains(ByRef objString As String) As BOOL
    262         If IndexOf(objString, 0, m_Length) >= 0 Then
    263             Return _System_TRUE
    264         Else
    265             Return _System_FALSE
    266         End If
    267     End Function
    268 
    269     Function Contains(lpszText As *Char) As BOOL
    270         If IndexOf(lpszText, 0, m_Length) >= 0 Then
    271             Return _System_TRUE
    272         Else
    273             Return _System_FALSE
    274         End If
    275     End Function
    276 
    277     Function IndexOf(lpszText As *Char) As Long
     229    Const Function Contains(ByRef objString As String) As Boolean
     230        Return IndexOf(objString, 0, m_Length) >= 0
     231    End Function
     232
     233    Const Function Contains(lpszText As *Char) As Boolean
     234        Return IndexOf(lpszText, 0, m_Length) >= 0
     235    End Function
     236
     237    Const Function IndexOf(lpszText As *Char) As Long
    278238        Return IndexOf(lpszText, 0, m_Length)
    279239    End Function
    280240
    281     Function IndexOf(lpszText As *Char, startIndex As Long) As Long
     241    Const Function IndexOf(lpszText As *Char, startIndex As Long) As Long
    282242        Return IndexOf(lpszText, startIndex, m_Length - startIndex)
    283243    End Function
    284244
    285     Function IndexOf(lpszText As *Char, startIndex As Long, count As Long) As Long
    286         Dim length As Long
    287         length = lstrlen(lpszText)
     245    Const Function IndexOf(lpszText As *Char, startIndex As Long, count As Long) As Long
     246        Dim length = lstrlen(lpszText)
    288247
    289248        If startIndex < 0 Then Return -1
     
    306265    End Function
    307266
    308     Function LastIndexOf(lpszText As *Char) As Long
     267    Const Function LastIndexOf(lpszText As *Char) As Long
    309268        Return LastIndexOf(lpszText, m_Length - 1, m_Length)
    310269    End Function
    311270
    312     Function LastIndexOf(lpszText As *Char, startIndex As Long) As Long
     271    Const Function LastIndexOf(lpszText As *Char, startIndex As Long) As Long
    313272        Return LastIndexOf(lpszText As *Char, startIndex, startIndex + 1)
    314273    End Function
    315274
    316     Function LastIndexOf(lpszText As *Char, startIndex As Long, count As Long) As Long
    317         Dim length As Long
    318         length = lstrlen(lpszText)
     275    Const Function LastIndexOf(lpszText As *Char, startIndex As Long, count As Long) As Long
     276        Dim length = lstrlen(lpszText)
    319277
    320278        If startIndex < 0 Or startIndex > m_Length - 1 Then Return -1
     
    337295    End Function
    338296
    339     Function StartsWith(lpszText As *Char) As BOOL
    340         If IndexOf(lpszText) = 0 Then
    341             Return _System_TRUE
    342         Else
    343             Return _System_FALSE
    344         End If
    345     End Function
    346 
    347     Function EndsWith(lpszText As *Char) As BOOL
    348         If LastIndexOf(lpszText) = m_Length - lstrlen(lpszText) Then
    349             Return _System_TRUE
    350         Else
    351             Return _System_FALSE
    352         End If
    353     End Function
    354 
    355     Function Insert(startIndex As Long, text As *Char) As Long
    356         Dim length As Long
    357         length = lstrlen(text)
    358 
    359         If startIndex < 0 Or startIndex > m_Length Then Return -1
    360 
    361         Dim newChars As *Char
    362         newChars = _System_malloc(SizeOf (Char) * (length + m_Length + 1))
    363         If newChars = 0 Then Return -1
    364 
    365         memcpy(newChars, Chars, SizeOf (Char) * startIndex)
    366         memcpy(VarPtr(newChars[startIndex]), text, SizeOf (Char) * length)
    367         memcpy(VarPtr(newChars[startIndex + length]), VarPtr(Chars[startIndex]), SizeOf (Char) * (m_Length - startIndex + 1))
    368 
    369         _System_free(Chars)
    370         Chars = newChars
    371         m_Length = length + m_Length
    372         Return m_Length
    373     End Function
    374 
    375     Function SubString(startIndex As Long) As String
     297    Const Function StartsWith(lpszText As *Char) As Boolean
     298        Return IndexOf(lpszText) = 0
     299    End Function
     300
     301    Const Function EndsWith(lpszText As *Char) As Boolean
     302        Return LastIndexOf(lpszText) = m_Length - lstrlen(lpszText)
     303    End Function
     304
     305    Const Function Insert(startIndex As Long, text As String) As String
     306        Return Insert(startIndex, text.Chars, text.Length)
     307    End Function
     308
     309    Const Function Insert(startIndex As Long, text As *Char) As String
     310        Return Insert(startIndex, text, lstrlen(text))
     311    End Function
     312
     313    Const Function Insert(startIndex As Long, text As *Char, length As Long) As String
     314        If startIndex < 0 Or startIndex > m_Length Or length < 0 Then
     315            Debug 'ArgumentOutOfRangeException
     316
     317        End If
     318        Insert.ReSize(m_Length + length)
     319        memcpy(Insert.Chars, Chars, SizeOf (Char) * startIndex)
     320        memcpy(VarPtr(Insert.Chars[startIndex]), text, SizeOf (Char) * length)
     321        memcpy(VarPtr(Insert.Chars[startIndex + length]), VarPtr(Chars[startIndex]), SizeOf (Char) * (m_Length - startIndex + 1))
     322    End Function
     323
     324    Const Function SubString(startIndex As Long) As String
    376325        Return SubString(startIndex, m_Length - startIndex)
    377326    End Function
    378327
    379     Function SubString(startIndex As Long, length As Long) As String
     328    Const Function SubString(startIndex As Long, length As Long) As String
    380329        If startIndex < 0 Or length <= 0 Then Return ""
    381330        If startIndex + length > m_Length Then Return ""
     
    388337    End Function
    389338
    390     Function Remove(startIndex As Long) As Long
    391         If startIndex < 0 Or startIndex > m_Length Then Return -1
    392         Chars[startIndex] = 0
    393         m_Length = startIndex
    394         Return m_Length
    395     End Function
    396 
    397     Function Remove(startIndex As Long, count As Long) As Long
    398         If startIndex < 0 Or count < 0 Then Return -1
    399         If startIndex + count > m_Length Then Return -1
    400 
    401         Dim newChars As *Char
    402         newChars = _System_malloc(SizeOf (Char) * (m_Length - count + 1))
    403         If newChars = 0 Then Return -1
    404 
    405         memcpy(newChars, Chars, SizeOf (Char) * startIndex)
    406         memcpy(VarPtr(newChars[startIndex]), VarPtr(Chars[startIndex + count]), SizeOf (Char) * (m_Length - startIndex - count))
    407         newChars[m_Length - count] = 0
    408 
    409         _System_free(Chars)
    410         Chars = newChars
    411         m_Length = m_Length - count
    412         Return m_Length
    413     End Function
    414 
    415     Function IsNullOrEmpty() As BOOL
    416         If m_Length = 0 Then
    417             Return _System_TRUE
    418         Else
    419             Return _System_FALSE
    420         End If
    421     End Function
    422 
    423 
    424     Sub Replace(oldChar As Char, newChar As Char)
    425         Dim i As Long
    426         For i = 0 To ELM(m_Length)
    427             If Chars[i] = oldChar Then
    428                 Chars[i] = newChar
     339    Const Function Remove(startIndex As Long) As String
     340        Remove.ReSize(startIndex)
     341        memcpy(Remove.Chars, This.Chars, SizeOf (Char) * startIndex)
     342    End Function
     343
     344    Const Function Remove(startIndex As Long, count As Long) As String
     345        Remove.ReSize(m_Length - count)
     346        memcpy(Remove.Chars, This.Chars, SizeOf (Char) * startIndex)
     347        memcpy(VarPtr(Remove.Chars[startIndex]), VarPtr(This.Chars[startIndex + count]), SizeOf (Char) * startIndex)
     348    End Function
     349/*
     350    Static Function IsNullOrEmpty(s As String) As Boolean
     351        If s <> Nothing Then
     352            If s.m_Length > 0 Then
     353                Return True
    429354            End If
    430         Next
    431     End Sub
    432 
    433     Sub Replace(ByRef oldStr As String, ByRef newStr As String)
    434         Replace(oldStr, oldStr.m_Length, newStr, newStr.m_Length)
    435     End Sub
    436 
    437     Sub Replace(oldStr As PCSTR, newStr As PCSTR)
    438         Replace(oldStr, lstrlen(oldStr), newStr, lstrlen(newStr))
    439     End Sub
    440 
    441     Sub Replace(oldStr As PCSTR, oldLen As Long, newStr As PCSTR, newLen As Long)
    442         Dim tempString As String
    443         With tempString
    444             Dim current = 0 As Long
    445             Do
    446                 Dim pos As Long
    447                 pos = IndexOf(oldStr, current)
    448                 If pos = -1 Then
    449                     Exit Do
     355        End If
     356        Return False
     357    End Function
     358*/
     359    Const Function Replace(oldChar As Char, newChar As Char) As String
     360        Replace = Copy(This)
     361        With Replace
     362            Dim i As Long
     363            For i = 0 To ELM(.m_Length)
     364                If .Chars[i] = .oldChar Then
     365                    .Chars[i] = .newChar
    450366                End If
    451                 .Append(Chars + current, pos - current)
    452                 .Append(newStr, newLen)
    453                 current = pos + oldLen
    454             Loop
    455             .Append(Chars + current, m_Length - current)
     367            Next
    456368        End With
    457         Swap(tempString)
    458     End Sub
     369    End Function
     370
     371    Const Function Replace(ByRef oldStr As String, ByRef newStr As String) As String
     372'       If oldStr = Nothing Then Throw ArgumentNullException
     373'
     374'       If newStr = Nothing Then
     375'           Return ReplaceCore(oldStr, oldStr.m_Length, "", 0)
     376'       Else
     377            Return ReplaceCore(oldStr, oldStr.m_Length, newStr, newStr.m_Length)
     378'       End If
     379    End Function
     380
     381    Const Function Replace(oldStr As *Char, newStr As *Char)
     382        If oldStr = 0 Then Debug 'Throw ArgumentNullException
     383        If newStr = 0 Then newStr = ""
     384        Return ReplaceCore(oldStr, lstrlen(oldStr), newStr, lstrlen(newStr)) As String
     385    End Function
     386
     387    Const Function Replace(oldStr As *Char, oldLen As Long, newStr As *Char, newLen As Long) As String
     388        If oldStr = 0 Then Debug 'Throw ArgumentNullException
     389        If newStr = 0 Then
     390            newStr = ""
     391            newLen = 0
     392        End If
     393        Return ReplaceCore(oldStr, oldLen, newStr, newLen)
     394    End Function
    459395
    460396    Sub ToLower()
     
    474410    Sub Swap(ByRef x As String)
    475411        Dim tempLen As Long
    476         Dim tempChars As PSTR
     412        Dim tempChars As *Char
    477413        tempLen = x.m_Length
    478414        tempChars = x.Chars
     
    485421    Override Function ToString() As String
    486422        Return This
     423    End Function
     424
     425    Static Function Copy(s As String) As String
     426        Copy.Resize(s.m_Length)
     427        memcpy(Copy.Chars, This.Chars, SizeOf (Char) * m_Length)
    487428    End Function
    488429
     
    504445    End Function
    505446
     447    Function ReplaceCore(oldStr As *Char, oldLen As Long, newStr As *Char, newLen As Long) As String
     448        If oldLen = 0 Then
     449            Debug 'Throw ArgumentException
     450        End If
     451        Dim tmp As String
     452        With tmp
     453            Dim current = 0 As Long
     454            Do
     455                Dim pos = IndexOf(oldStr, current)
     456                If pos = -1 Then
     457                    Exit Do
     458                End If
     459                .Append(VarPtr(Chars[current]), pos - current)
     460                .Append(newStr, newLen)
     461                current = pos + oldLen
     462            Loop
     463            .Append(VarPtr(Chars[current]), m_Length - current)
     464        End With
     465        Return tmp
     466    End Function
     467
    506468End Class
    507469
  • Include/Classes/System/Windows/Forms/Control.ab

    r77 r132  
    5656Class AsyncInvokeData
    5757Public
    58     FuncPtr As *Function(p As VoidPtr) As VoidPtr, p As VoidPtr
     58    FuncPtr As *Function(p As VoidPtr) As VoidPtr
    5959    Data As *VoidPtr
    6060    AsyncResult As *AsyncResultForInvoke
     
    6464    Inherits IWin32Window
    6565Public
    66     ' Properties
     66    '---------------------------------------------------------------------------
     67    ' Public Properties
    6768
    6869    Function AllowDrop() As BOOL
     
    223224    End Sub
    224225
     226    Function Parent() As *Control
     227        Return parent
     228    End Function
     229
     230    Static Function DefaultBackColor() As Color
     231        Return Color.FromArgb(255, 255, 255)
     232    End Function
     233
     234    '---------------------------------------------------------------------------
    225235    ' Constractors
    226236
     
    240250    End Sub
    241251
    242     Sub Control(text As String, left As Long, top As Long, width As Long, height As Long)
     252    Sub Control(ByRef text As String, left As Long, top As Long, width As Long, height As Long)
    243253        This.text = text
    244254        bkColor = DefaultBackColor
     
    252262    End Sub
    253263
    254     Function Parent() As *Control
    255         Return parent
    256     End Function
    257 
    258     Static Function DefaultBackColor() As Color
    259         Return Color.FromArgb(255, 255, 255)
    260     End Function
    261 
     264    '---------------------------------------------------------------------------
    262265    ' Destractor
    263266
     
    268271    End Sub
    269272
    270     ' Methods
     273    '---------------------------------------------------------------------------
     274    ' Public Methods
    271275
    272276    ' 同期関数呼出、Controlが作成されたスレッドで関数を実行する。
     
    345349
    346350Protected
    347     ' Properties
     351    '---------------------------------------------------------------------------
     352    ' Protected Properties
    348353'   Const Virtual Function CanRaiseEvents() As BOOL
    349354    Virtual Function CreateParams() As *CreateParams
     
    364369'   Virtual Sub Cursor(ByRef c As Cursor)
    365370
    366     ' Methods
     371    '---------------------------------------------------------------------------
     372    ' Protected Methods
    367373    Virtual Sub CreateHandle()
    368374        Dim createParams = CreateParams()
     
    406412                Case WM_ERASEBKGND
    407413                    ' OnPaintBackgroundに移すべき
    408                     Dim hdc As HDC
    409                     hdc = .WParam As HDC
     414                    Dim hdc = .WParam As HDC
    410415                    Dim hbr = CreateSolidBrush(bkColor.ToCOLORREF())
    411416                    Dim hbrOld = SelectObject(hdc, hbr)
    412                     Dim rc As RECT
    413                     rc = wnd.ClientRect
     417                    Dim rc = wnd.ClientRect
    414418                    Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom)
    415419                    SelectObject(hdc, hbrOld)
  • Include/basic/function.sbp

    r126 r132  
    11371137End Function
    11381138
     1139Function _System_StrCmp(s1 As PCSTR, s2 As PCSTR) As Long
     1140    Dim i = 0 As SIZE_T
     1141    While s1[i] = s2[i]
     1142        If s1[i] = 0 Then
     1143            Exit While
     1144        End If
     1145        i++
     1146    Wend
     1147    _System_StrCmp = s1[i] - s2[i]
     1148End Function
     1149
     1150Function _System_StrCmp(s1 As PCWSTR, s2 As PCWSTR) As Long
     1151    Dim i = 0 As SIZE_T
     1152    While s1[i] = s2[i]
     1153        If s1[i] = 0 Then
     1154            Exit While
     1155        End If
     1156        i++
     1157    Wend
     1158    _System_StrCmp = s1[i] - s2[i]
     1159End Function
    11391160#endif '_INC_FUNCTION
  • Include/basic/prompt.sbp

    r127 r132  
    136136                .y++
    137137            Else
    138                 Dim currentLineCharInfo = _PromptSys_TextLine[.y].CharInfo As *_PromptSys_CharacterInformation
     138                Dim currentLineCharInfo = _PromptSys_TextLine[.y].CharInfo
    139139                _PromptSys_TextLine[.y].Text[.x] = buf[i2]
    140140                currentLineCharInfo[.x].ForeColor = _PromptSys_NowTextColor
     
    262262
    263263        CreateCaret(hwnd, 0, 9, 6)
    264         SetCaretPos(_PromptSys_CurPos.x * _PromptSys_FontSize.cx, (_PromptSys_CurPos.y + 1) * _PromptSys_FontSize.cy - 7)
     264        With _PromptSys_CurPos
     265            SetCaretPos(_PromptSys_TextLine[.y].CharInfo[.x].StartPos, (.y + 1) * _PromptSys_FontSize.cy - 7)
     266        End With
    265267        ShowCaret(hwnd)
    266268    End If
     
    353355
    354356        memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), str, size)
    355         _PromptSys_InputLen += size
     357        _PromptSys_InputLen += size \ SizeOf (Char)
    356358
    357359        Dim tempStr As String(str, size \ SizeOf (Char))
Note: See TracChangeset for help on using the changeset viewer.