1  'string.sbp


2  '文字列変数の操作用


3 


4  #ifndef _INC_BASIC_STRING


5  #define _INC_BASIC_STRING


6 


7  #require <Classes/System/String.ab>


8  #require <Classes/System/Text/StringBuilder.ab>


9 


10  Function StrPtr(s As String) As *StrChar


11  StrPtr = s.StrPtr


12  End Function


13  'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている


14 


15  Function ZeroString(length As Long) As System.Text.StringBuilder


16  ZeroString = New System.Text.StringBuilder


17  ZeroString.Length = length


18  End Function


19 


20  Function MakeStr(psz As PSTR) As String


21  Return New String(psz)


22  End Function


23 


24  Function MakeStr(psz As PWSTR) As String


25  Return New String(psz)


26  End Function


27 


28  Dim _System_AllocForConvertedString As *Function(size As SIZE_T) As VoidPtr


29  _System_AllocForConvertedString = AddressOf (GC_malloc_atomic)


30 


31  Function GetStr(psz As PSTR, ByRef wcs As PWSTR) As SIZE_T


32  If psz <> 0 Then


33  Return GetStr(psz, lstrlenA(psz) As SIZE_T, wcs)


34  Else


35  Return 0


36  End If


37  End Function


38 


39  Function GetStr(psz As PSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T


40  If psz = 0 Then Return 0


41  Dim lenWCS = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, len As Long, 0, 0)


42  wcs = _System_AllocForConvertedString(SizeOf (WCHAR) * (lenWCS + 1)) As PWSTR


43  GetStr = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, len As Long, wcs, lenWCS)


44  wcs[GetStr] = 0


45  End Function


46 


47  Function GetStr(psz As PWSTR, ByRef wcs As PWSTR) As SIZE_T


48  wcs = psz


49  If psz <> 0 Then


50  Return lstrlenW(psz) As SIZE_T


51  Else


52  Return 0


53  End If


54  End Function


55 


56  Function GetStr(psz As PWSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T


57  wcs = psz


58  If psz <> 0 Then


59  Return len


60  Else


61  Return 0


62  End If


63  End Function


64 


65  Function GetStr(psz As PWSTR, ByRef mbs As PSTR) As SIZE_T


66  If psz = 0 Then


67  Return 0


68  Else


69  Return GetStr(psz, lstrlenW(psz) As SIZE_T, mbs)


70  End If


71  End Function


72 


73  Function GetStr(psz As PWSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T


74  If psz = 0 Then Return 0


75  Dim lenMBS = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, len As Long, 0, 0, 0, 0)


76  mbs = _System_AllocForConvertedString(SizeOf (SByte) * (lenMBS + 1)) As PSTR


77  GetStr = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, len As Long, mbs, lenMBS, 0, 0) As SIZE_T


78  mbs[GetStr] = 0


79  End Function


80 


81  Function GetStr(psz As PSTR, ByRef mbs As PSTR) As SIZE_T


82  mbs = psz


83  If psz <> 0 Then


84  Return lstrlenA(psz) As SIZE_T


85  Else


86  Return 0


87  End If


88  End Function


89 


90  Function GetStr(psz As PSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T


91  mbs = psz


92  If psz <> 0 Then


93  Return len


94  Else


95  Return 0


96  End If


97  End Function


98 


99  Function GetStr(s As String, ByRef mbs As PSTR) As SIZE_T


100  Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)


101  End Function


102 


103  Function GetStr(s As String, ByRef wcs As PWSTR) As SIZE_T


104  Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)


105  End Function


106 


107  Function GetWCStr(psz As PSTR, ByRef wcs As PWSTR) As SIZE_T


108  Return GetStr(psz, wcs)


109  End Function


110 


111  Function GetWCStr(psz As PSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T


112  Return GetStr(psz, len, wcs)


113  End Function


114 


115  Function GetWCStr(psz As PWSTR, ByRef wcs As PWSTR) As SIZE_T


116  Return GetStr(psz, wcs)


117  End Function


118 


119  Function GetWCStr(psz As PWSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T


120  Return GetStr(psz, len, wcs)


121  End Function


122 


123  Function GetWCStr(s As String, ByRef wcs As PWSTR) As SIZE_T


124  Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)


125  End Function


126 


127  Function GetMBStr(psz As PWSTR, ByRef mbs As PSTR) As SIZE_T


128  Return GetStr(psz, mbs)


129  End Function


130 


131  Function GetMBStr(psz As PWSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T


132  Return GetStr(psz, len, mbs)


133  End Function


134 


135  Function GetMBStr(psz As PSTR, ByRef mbs As PSTR) As SIZE_T


136  Return GetStr(psz, mbs)


137  End Function


138 


139  Function GetMBStr(psz As PSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T


140  Return GetStr(psz, len, mbs)


141  End Function


142 


143  Function GetMBStr(s As String, ByRef mbs As PSTR) As SIZE_T


144  Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)


145  End Function


146 


147  Function GetTCStr(psz As PSTR, ByRef tcs As PCTSTR) As SIZE_T


148  Return GetStr(psz, tcs)


149  End Function


150 


151  Function GetTCStr(psz As PSTR, len As SIZE_T, ByRef tcs As PCTSTR) As SIZE_T


152  Return GetStr(psz, len, tcs)


153  End Function


154 


155  Function GetTCStr(psz As PWSTR, ByRef tcs As PCTSTR) As SIZE_T


156  Return GetStr(psz, tcs)


157  End Function


158 


159  Function GetTCStr(psz As PWSTR, len As SIZE_T, ByRef tcs As PCTSTR) As SIZE_T


160  Return GetStr(psz, len, tcs)


161  End Function


162 


163  Function GetTCStr(s As String, ByRef tcs As PCTSTR) As SIZE_T


164  Return GetStr(s.StrPtr, s.Length As SIZE_T, tcs)


165  End Function


166 


167  Function GetSCStr(psz As PSTR, ByRef ss As *StrChar) As SIZE_T


168  Return GetStr(psz, ss)


169  End Function


170 


171  Function GetSCStr(psz As PSTR, len As SIZE_T, ByRef ss As *StrChar) As SIZE_T


172  Return GetStr(psz, len, ss)


173  End Function


174 


175  Function GetSCStr(psz As PWSTR, ByRef ss As *StrChar) As SIZE_T


176  Return GetStr(psz, ss)


177  End Function


178 


179  Function GetSCStr(psz As PWSTR, len As SIZE_T, ByRef ss As *StrChar) As SIZE_T


180  Return GetStr(psz, len, ss)


181  End Function


182 


183  Function GetSCStr(s As String, ByRef ss As *StrChar) As SIZE_T


184  Return GetStr(s.StrPtr, s.Length As SIZE_T, ss)


185  End Function


186 


187  Function ToWCStr(psz As PSTR) As PWSTR


188  GetStr(psz, ToWCStr)


189  End Function


190 


191  Function ToWCStr(psz As PSTR, len As SIZE_T) As PWSTR


192  GetStr(psz, len, ToWCStr)


193  End Function


194 


195  Function ToWCStr(psz As PWSTR) As PWSTR


196  GetStr(psz, ToWCStr)


197  End Function


198 


199  Function ToWCStr(psz As PWSTR, len As SIZE_T) As PWSTR


200  GetStr(psz, len, ToWCStr)


201  End Function


202 


203  Function ToWCStr(s As String) As PWSTR


204  GetStr(s.StrPtr, s.Length As SIZE_T, ToWCStr)


205  End Function


206 


207  Function ToMBStr(psz As PSTR) As PSTR


208  GetStr(psz, ToMBStr)


209  End Function


210 


211  Function ToMBStr(psz As PSTR, len As SIZE_T) As PSTR


212  GetStr(psz, len, ToMBStr)


213  End Function


214 


215  Function ToMBStr(psz As PWSTR) As PSTR


216  GetStr(psz, ToMBStr)


217  End Function


218 


219  Function ToMBStr(psz As PWSTR, len As SIZE_T) As PSTR


220  GetStr(psz, len, ToMBStr)


221  End Function


222 


223  Function ToMBStr(s As String) As PSTR


224  GetStr(s.StrPtr, s.Length As SIZE_T, ToMBStr)


225  End Function


226 


227  Function ToTCStr(psz As PSTR) As PCTSTR


228  GetStr(psz, ToTCStr)


229  End Function


230 


231  Function ToTCStr(psz As PSTR, len As SIZE_T) As PCTSTR


232  GetStr(psz, len, ToTCStr)


233  End Function


234 


235  Function ToTCStr(psz As PWSTR) As PCTSTR


236  GetStr(psz, ToTCStr)


237  End Function


238 


239  Function ToTCStr(psz As PWSTR, len As SIZE_T) As PCTSTR


240  GetStr(psz, len, ToTCStr)


241  End Function


242 


243  Function ToTCStr(s As String) As PCTSTR


244  GetStr(s.StrPtr, s.Length As SIZE_T, ToTCStr)


245  End Function


246 


247  Function ToSCStr(psz As PSTR) As *StrChar


248  GetStr(psz, ToSCStr)


249  End Function


250 


251  Function ToSCStr(psz As PSTR, len As SIZE_T) As *StrChar


252  GetStr(psz, len, ToSCStr)


253  End Function


254 


255  Function ToSCStr(psz As PWSTR) As *StrChar


256  GetStr(psz, ToSCStr)


257  End Function


258 


259  Function ToSCStr(psz As PWSTR, len As SIZE_T) As *StrChar


260  GetStr(psz, len, ToSCStr)


261  End Function


262 


263  Function ToSCStr(s As String) As *StrChar


264  GetStr(s.StrPtr, s.Length As SIZE_T, ToSCStr)


265  End Function


266 


267  #ifdef __STRING_IS_NOT_UNICODE


268  Typedef BoxedStrChar = System.SByte


269  #else


270  TypeDef BoxedStrChar = System.UInt16


271  #endif


272 


273  #endif '_INC_BASIC_STRING

