Changeset 457 for trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab
- Timestamp:
- Mar 6, 2008, 9:49:43 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab
r400 r457 205 205 */ 206 206 Function FormatFloatF_Core(s As String, e As Long, negative As Boolean, precision As DWord, ByRef flags As FormatFlags) As System.Text.StringBuilder 207 FormatFloatF_Core = New System.Text.StringBuilder 207 FormatFloatF_Core = New System.Text.StringBuilder(128) 208 208 With FormatFloatF_Core 209 209 AppendSign(FormatFloatF_Core, negative, flags) … … 818 818 819 819 Dim sb = New System.Text.StringBuilder 820 If sb.Length = &hfeeefeee Then Debug821 820 With sb 822 821 Dim prefixFunc = tr.Prefix 823 822 Dim prefix = prefixFunc(x, flags) 824 823 sb.Append(prefix) 825 If sb.Length = &hfeeefeee Then Debug826 824 827 825 Dim prefixLen = 0 As DWord … … 830 828 End If 831 829 832 Dim buf = GC_malloc_atomic((tr.MaxSize + 1) * SizeOf (StrChar)) As *StrChar 830 ' Dim buf = GC_malloc_atomic((tr.MaxSize + 1) * SizeOf (StrChar)) As *StrChar 831 Dim buf[MaxSizeLO] As StrChar 833 832 Dim convertFunc = tr.Convert 834 833 Dim bufStartPos = convertFunc(buf, x, flags) 835 834 836 If sb.Length = &hfeeefeee Then Debug837 835 Dim len = (tr.MaxSize - bufStartPos) As Long 838 836 If len < 0 Then … … 844 842 845 843 .Append(buf, bufStartPos + 1, len) 846 If sb.Length = &hfeeefeee Then Debug847 844 848 845 AdjustFieldWidth(sb, field, flags And (Not (Sign Or Blank)), prefixLen) 849 If sb.Length = &hfeeefeee Then Debug850 846 End With 851 847 FormatIntegerEx = sb.ToString() … … 855 851 End If 856 852 End Function 853 Sub FormatIntegerEx(sb As System.Text.StringBuilder, ByRef tr As IntegerConvertTraits, x As QWord, d As DWord, field As DWord, flags As FormatFlags) 854 855 If d = DWORD_MAX Then 856 d = 1 857 Else 858 '精度が指定されているとき、ゼロフラグは無視される。 859 '仕様上、左揃えのときも無視されるが、それはAdjustFieldWidthが行ってくれる。 860 flags And= Not Zero 861 End If 862 863 Dim lastLength = sb.Length 864 865 With sb 866 Dim prefixFunc = tr.Prefix 867 Dim prefix = prefixFunc(x, flags) 868 sb.Append(prefix) 869 870 Dim prefixLen = 0 As DWord 871 If String.IsNullOrEmpty(prefix) = False Then 872 prefixLen = prefix.Length As DWord 873 End If 874 875 ' Dim buf = GC_malloc_atomic((tr.MaxSize + 1) * SizeOf (StrChar)) As *StrChar 876 Dim buf[MaxSizeLO] As StrChar 877 Dim convertFunc = tr.Convert 878 Dim bufStartPos = convertFunc(buf, x, flags) 879 880 Dim len = (tr.MaxSize - bufStartPos) As Long 881 If len < 0 Then 882 Debug 883 End If 884 If len < d Then 885 .Append(&h30 As StrChar, d - len) 886 End If 887 888 .Append(buf, bufStartPos + 1, len) 889 890 AdjustFieldWidth(sb, field, flags And (Not (Sign Or Blank)), prefixLen, lastLength) 891 End With 892 Dim t = sb.ToString() 893 894 If (flags And Cap) = 0 Then 895 Dim len = sb.Length 896 Dim i As Long 897 For i = lastLength To ELM(len) 898 sb[i] = CType.ToLower(sb[i]) 899 Next 900 End If 901 End Sub 857 902 858 903 /*! … … 864 909 865 910 /*! 866 @brief 文字列をフィールド幅まで満たされるように空白などを挿入する。911 @brief 書式化の仕上げとして、変換部分がフィールド幅まで満たされるように空白などを挿入する。 867 912 @author Egtra 868 913 @date 2007/10/13 … … 872 917 @param[in] flags フラグ 873 918 @param[in] prefixLen (あれば)接頭辞の文字数。ゼロ埋めする際、この数だけ挿入位置を後ろにする。 919 @param[in] offset 変換した部分へのオフセット。AppendではなくInsertを行う際に用いられる。 874 920 sbが"-1"のように負符号を持っている場合は、呼出元でSignフラグ(またはBlank)を立てること。 875 921 */ 876 Sub AdjustFieldWidth(sb As System.Text.StringBuilder, field As DWord, flags As FormatFlags, prefixLen = 0 As DWord )922 Sub AdjustFieldWidth(sb As System.Text.StringBuilder, field As DWord, flags As FormatFlags, prefixLen = 0 As DWord, offset = 0 As Long) 877 923 With sb 878 If .Length < field Then 879 Dim embeddedSize = field - .Length 924 Dim len = .Length - offset 925 If len < field Then 926 Dim embeddedSize = field - len 880 927 If flags And LeftSide Then 881 928 .Append(&h20, embeddedSize) 882 929 Else 883 Dim insPos As Long884 930 If (flags And Zero) <> 0 Then 931 offset += prefixLen 885 932 If (flags And Blank) Or (flags And Sign) Then 886 insPos++933 offset++ 887 934 End If 888 insPos += prefixLen 889 .Insert(insPos, String$(embeddedSize, "0")) 935 .Insert(offset, String$(embeddedSize, "0")) 890 936 Else 891 .Insert( insPos, String$(embeddedSize, " "))937 .Insert(offset, String$(embeddedSize, " ")) 892 938 End If 893 939 End If … … 1005 1051 End If 1006 1052 1007 s.Append(FormatIntegerEx(ByVal traits, x, precision, field, flags)) 1053 ' s.Append(FormatIntegerEx(ByVal traits, x, precision, field, flags)) 1054 FormatIntegerEx(s, ByVal traits, x, precision, field, flags) 1008 1055 End Sub 1009 1056 … … 1028 1075 Do 1029 1076 Dim c = s[i] 1030 If Not IsDigit(c) Then Exit Do1077 If Not CType.IsDigit(c) Then Exit Do 1031 1078 StrToLong *= 10 1032 1079 StrToLong += ((c As DWord) And &h0f) As Long … … 1037 1084 End If 1038 1085 p = VarPtr(s[i]) 1039 End Function1040 1041 /*!1042 @brief 文字が十進数字かどうか調べる。1043 @author Egtra1044 @date 2007/11/111045 @param[in] c 調べる文字1046 @retval True 0から9の文字である1047 @retval False そうでない1048 */1049 Function IsDigit(c As StrChar) As Boolean1050 Dim dw = (c As DWord)1051 IsDigit = (dw - &h30) < 101052 1086 End Function 1053 1087
Note:
See TracChangeset
for help on using the changeset viewer.