• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

OpenTweenのfork


Commit MetaInfo

修訂0d9d02757d56072b1b9975bd5628c44930293a76 (tree)
時間2012-02-22 19:47:44
作者Egtra <yusuke.ichinohe@gmai...>
CommiterKimura Youichi

Log Message

Port RadixConvert.vg to C#

Change Summary

差異

--- a/Tween/RadixConvert.vb
+++ /dev/null
@@ -1,465 +0,0 @@
1-' Tween - Client of Twitter
2-' Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3-' (c) 2008-2011 Moz (@syo68k)
4-' (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5-' (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6-' (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7-' All rights reserved.
8-'
9-' This file is part of Tween.
10-'
11-' This program is free software; you can redistribute it and/or modify it
12-' under the terms of the GNU General Public License as published by the Free
13-' Software Foundation; either version 3 of the License, or (at your option)
14-' any later version.
15-'
16-' This program is distributed in the hope that it will be useful, but
17-' WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18-' or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19-' for more details.
20-'
21-' You should have received a copy of the GNU General Public License along
22-' with this program. If not, see <http://www.gnu.org/licenses/>, or write to
23-' the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
24-' Boston, MA 02110-1301, USA.
25-
26-Imports System.Text
27-
28-
29-Public Class RadixConvert
30-
31- ''' <summary>
32- ''' ƒCƒ“ƒXƒ^ƒ“ƒX‰»‚ð‹ÖŽ~‚µ‚Ä‚¢‚Ü‚·B
33- ''' </summary>
34- Private Sub New()
35-
36- End Sub
37-
38-#Region "Int16Œ^‚¨‚æ‚ÑUInt16Œ^—p‚̃ƒ\ƒbƒhŒQ"
39-
40- ''' <summary>
41- ''' 3`36i”‚̐”’l•¶Žš—ñ‚ðInt16Œ^‚̐”’l‚É•ÏŠ·‚µ‚Ü‚·B
42- ''' </summary>
43- ''' <remarks>
44- ''' ¦2^8^10^16i”‚́AConvert.ToInt16ƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
45- ''' ¦{‚â|‚Ì•„†‚â0x‚Ȃǂ̃vƒŒƒtƒBƒbƒNƒX‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
46- ''' ¦ˆø”‚ƂȂ鐔’l•¶Žš—ñ‚ɁAƒXƒy[ƒX‚È‚Ç‚Ì•¶Žš‚ðŠÜ‚ß‚È‚¢‚Å‚­‚¾‚³‚¢B
47- ''' </remarks>
48- ''' <param name="s">”’l•¶Žš—ñ</param>
49- ''' <param name="radix">Šî”</param>
50- ''' <returns>”’l</returns>
51- Public Shared Function ToInt16(ByVal s As String, ByVal radix As Integer) As Short
52-
53- Dim digit As ULong = ToUInt64(s, radix)
54- CheckDigitOverflow(digit, Int16.MaxValue)
55- Return CType(digit, Short)
56-
57- End Function
58-
59- ''' <summary>
60- ''' 3`36i”‚̐”’l•¶Žš—ñ‚ðUInt16Œ^‚̐”’l‚É•ÏŠ·‚µ‚Ü‚·B
61- ''' </summary>
62- ''' <remarks>
63- ''' ¦2^8^10^16i”‚́AConvert.ToUInt16ƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
64- ''' ¦{‚â|‚Ì•„†‚â0x‚Ȃǂ̃vƒŒƒtƒBƒbƒNƒX‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
65- ''' ¦ˆø”‚ƂȂ鐔’l•¶Žš—ñ‚ɁAƒXƒy[ƒX‚È‚Ç‚Ì•¶Žš‚ðŠÜ‚ß‚È‚¢‚Å‚­‚¾‚³‚¢B
66- ''' </remarks>
67- ''' <param name="s">”’l•¶Žš—ñ</param>
68- ''' <param name="radix">Šî”</param>
69- ''' <returns>”’l</returns>
70- Public Shared Function ToUInt16(ByVal s As String, ByVal radix As Integer) As UShort
71-
72- Dim digit As ULong = ToUInt64(s, radix)
73- CheckDigitOverflow(digit, UInt16.MaxValue)
74- Return CType(digit, UShort)
75-
76- End Function
77-
78- ''' <summary>
79- ''' UInt16Œ^‚̐”’l‚ð3`36i”‚̐”’l•¶Žš—ñ‚É•ÏŠ·‚µ‚Ü‚·B
80- ''' </summary>
81- ''' <remarks>
82- ''' ¦2^8^10^16i”‚́AConvert.ToStringƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
83- ''' ¦|•„†‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
84- ''' </remarks>
85- ''' <param name="n">”’l</param>
86- ''' <param name="radix">Šî”</param>
87- ''' <param name="uppercase">‘啶Žš‚©itruejA¬•¶Žš‚©ifalsej</param>
88- ''' <returns>”’l•¶Žš—ñ</returns>
89- Public Overloads Shared Function ToString(ByVal n As Short, ByVal radix As Integer, ByVal uppercase As Boolean) As String
90-
91- Return ToString(CType(n, ULong), radix, uppercase)
92-
93- End Function
94-
95- ''' <summary>
96- ''' UInt16Œ^‚̐”’l‚ð3`36i”‚̐”’l•¶Žš—ñ‚É•ÏŠ·‚µ‚Ü‚·B
97- ''' </summary>
98- ''' <remarks>
99- ''' ¦2^8^10^16i”‚́AConvert.ToStringƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
100- ''' ¦|•„†‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
101- ''' </remarks>
102- ''' <param name="n">”’l</param>
103- ''' <param name="radix">Šî”</param>
104- ''' <param name="uppercase">‘啶Žš‚©itruejA¬•¶Žš‚©ifalsej</param>
105- ''' <returns>”’l•¶Žš—ñ</returns>
106- Public Overloads Shared Function ToString(ByVal n As UShort, ByVal radix As Integer, ByVal uppercase As Boolean) As String
107-
108- Return ToString(CType(n, ULong), radix, uppercase)
109-
110- End Function
111-
112-#End Region
113-
114-#Region "Int32Œ^‚¨‚æ‚ÑUInt32Œ^—p‚̃ƒ\ƒbƒhŒQ"
115-
116- ''' <summary>
117- ''' 3`36i”‚̐”’l•¶Žš—ñ‚ðInt32Œ^‚̐”’l‚É•ÏŠ·‚µ‚Ü‚·B
118- ''' </summary>
119- ''' <remarks>
120- ''' ¦2^8^10^16i”‚́AConvert.ToInt32ƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
121- ''' ¦{‚â|‚Ì•„†‚â0x‚Ȃǂ̃vƒŒƒtƒBƒbƒNƒX‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
122- ''' ¦ˆø”‚ƂȂ鐔’l•¶Žš—ñ‚ɁAƒXƒy[ƒX‚È‚Ç‚Ì•¶Žš‚ðŠÜ‚ß‚È‚¢‚Å‚­‚¾‚³‚¢B
123- ''' </remarks>
124- ''' <param name="s">”’l•¶Žš—ñ</param>
125- ''' <param name="radix">Šî”</param>
126- ''' <returns>”’l</returns>
127- Public Shared Function ToInt32(ByVal s As String, ByVal radix As Integer) As Integer
128-
129- Dim digit As ULong = ToUInt64(s, radix)
130- CheckDigitOverflow(digit, Int32.MaxValue)
131- Return CType(digit, Integer)
132-
133- End Function
134-
135- ''' <summary>
136- ''' 3`36i”‚̐”’l•¶Žš—ñ‚ðUInt32Œ^‚̐”’l‚É•ÏŠ·‚µ‚Ü‚·B
137- ''' </summary>
138- ''' <remarks>
139- ''' ¦2^8^10^16i”‚́AConvert.ToUInt32ƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
140- ''' ¦{‚â|‚Ì•„†‚â0x‚Ȃǂ̃vƒŒƒtƒBƒbƒNƒX‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
141- ''' ¦ˆø”‚ƂȂ鐔’l•¶Žš—ñ‚ɁAƒXƒy[ƒX‚È‚Ç‚Ì•¶Žš‚ðŠÜ‚ß‚È‚¢‚Å‚­‚¾‚³‚¢B
142- ''' </remarks>
143- ''' <param name="s">”’l•¶Žš—ñ</param>
144- ''' <param name="radix">Šî”</param>
145- ''' <returns>”’l</returns>
146- Public Shared Function ToUInt32(ByVal s As String, ByVal radix As Integer) As UInteger
147-
148- Dim digit As ULong = ToUInt64(s, radix)
149- CheckDigitOverflow(digit, UInt32.MaxValue)
150- Return CType(digit, UInteger)
151-
152- End Function
153-
154- ''' <summary>
155- ''' UInt32Œ^‚̐”’l‚ð3`36i”‚̐”’l•¶Žš—ñ‚É•ÏŠ·‚µ‚Ü‚·B
156- ''' </summary>
157- ''' <remarks>
158- ''' ¦2^8^10^16i”‚́AConvert.ToStringƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
159- ''' ¦|•„†‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
160- ''' </remarks>
161- ''' <param name="n">”’l</param>
162- ''' <param name="radix">Šî”</param>
163- ''' <param name="uppercase">‘啶Žš‚©itruejA¬•¶Žš‚©ifalsej</param>
164- ''' <returns>”’l•¶Žš—ñ</returns>
165- Public Overloads Shared Function ToString(ByVal n As Integer, ByVal radix As Integer, ByVal uppercase As Boolean) As String
166-
167- Return ToString(CType(n, ULong), radix, uppercase)
168-
169- End Function
170-
171- ''' <summary>
172- ''' UInt32Œ^‚̐”’l‚ð3`36i”‚̐”’l•¶Žš—ñ‚É•ÏŠ·‚µ‚Ü‚·B
173- ''' </summary>
174- ''' <remarks>
175- ''' ¦2^8^10^16i”‚́AConvert.ToStringƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
176- ''' ¦|•„†‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
177- ''' </remarks>
178- ''' <param name="n">”’l</param>
179- ''' <param name="radix">Šî”</param>
180- ''' <param name="uppercase">‘啶Žš‚©itruejA¬•¶Žš‚©ifalsej</param>
181- ''' <returns>”’l•¶Žš—ñ</returns>
182- Public Overloads Shared Function ToString(ByVal n As UInteger, ByVal radix As Integer, ByVal uppercase As Boolean) As String
183-
184- Return ToString(CType(n, ULong), radix, uppercase)
185-
186- End Function
187-
188-#End Region
189-
190-#Region "Int64Œ^‚¨‚æ‚ÑUInt64Œ^—p‚̃ƒ\ƒbƒhŒQ"
191-
192- ''' <summary>
193- ''' 3`36i”‚̐”’l•¶Žš—ñ‚ðInt64Œ^‚̐”’l‚É•ÏŠ·‚µ‚Ü‚·B
194- ''' </summary>
195- ''' <remarks>
196- ''' ¦2^8^10^16i”‚́AConvert.ToInt64ƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
197- ''' ¦{‚â|‚Ì•„†‚â0x‚Ȃǂ̃vƒŒƒtƒBƒbƒNƒX‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
198- ''' ¦ˆø”‚ƂȂ鐔’l•¶Žš—ñ‚ɁAƒXƒy[ƒX‚È‚Ç‚Ì•¶Žš‚ðŠÜ‚ß‚È‚¢‚Å‚­‚¾‚³‚¢B
199- ''' </remarks>
200- ''' <param name="s">”’l•¶Žš—ñ</param>
201- ''' <param name="radix">Šî”</param>
202- ''' <returns>”’l</returns>
203- Public Shared Function ToInt64(ByVal s As String, ByVal radix As Integer) As Long
204-
205- Dim digit As ULong = ToUInt64(s, radix)
206- CheckDigitOverflow(digit, Int64.MaxValue)
207- Return CType(digit, Long)
208-
209- End Function
210-
211- ''' <summary>
212- ''' 3`36i”‚̐”’l•¶Žš—ñ‚ðUInt64Œ^‚̐”’l‚É•ÏŠ·‚µ‚Ü‚·B
213- ''' </summary>
214- ''' <remarks>
215- ''' ¦2^8^10^16i”‚́AConvert.ToUInt64ƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
216- ''' ¦{‚â|‚Ì•„†‚â0x‚Ȃǂ̃vƒŒƒtƒBƒbƒNƒX‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
217- ''' ¦ˆø”‚ƂȂ鐔’l•¶Žš—ñ‚ɁAƒXƒy[ƒX‚È‚Ç‚Ì•¶Žš‚ðŠÜ‚ß‚È‚¢‚Å‚­‚¾‚³‚¢B
218- ''' </remarks>
219- ''' <param name="s">”’l•¶Žš—ñ</param>
220- ''' <param name="radix">Šî”</param>
221- ''' <returns>”’l</returns>
222- Public Shared Function ToUInt64(ByVal s As String, ByVal radix As Integer) As ULong
223-
224- ' ˆø”‚ðƒ`ƒFƒbƒN‚ð‚·‚é
225- CheckNumberArgument(s)
226- CheckRadixArgument(radix)
227-
228- Dim curValue As ULong = 0 ' •ÏŠ·’†‚̐”’l
229- Dim maxValue As ULong = CType(UInt64.MaxValue / CType(radix, ULong), ULong) ' Å‘å’l‚Ì1‚¯‚½‘O‚̐”’l
230-
231- ' ”’l•¶Žš—ñ‚ð‰ðÍ‚µ‚Đ”’l‚É•ÏŠ·‚·‚é
232- Dim num As Char ' ˆ—’†‚Ì1‚¯‚½‚̐”’l•¶Žš—ñ
233- Dim digit As Integer ' ˆ—’†‚Ì1‚¯‚½‚̐”’l
234- Dim length As Integer = s.Length
235- For i As Integer = 0 To length - 1
236- num = s(i)
237- digit = GetDigitFromNumber(num)
238- CheckDigitOutOfRange(digit, radix)
239-
240- ' ŽŸ‚Éradix‚ðŠ|‚¯‚é‚Æ‚«‚ɐ”’l‚ªƒI[ƒo[ƒtƒ[‚µ‚È‚¢‚©‚ðŽ–‘O‚Ƀ`ƒFƒbƒN‚·‚é
241- CheckDigitOverflow(curValue, maxValue)
242- curValue = curValue * CType(radix, ULong) + CType(digit, ULong)
243- Next
244-
245- Return curValue
246-
247- End Function
248-
249- ''' <summary>
250- ''' UInt64Œ^‚̐”’l‚ð3`36i”‚̐”’l•¶Žš—ñ‚É•ÏŠ·‚µ‚Ü‚·B
251- ''' </summary>
252- ''' <remarks>
253- ''' ¦2^8^10^16i”‚́AConvert.ToStringƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
254- ''' ¦|•„†‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
255- ''' </remarks>
256- ''' <param name="n">”’l</param>
257- ''' <param name="radix">Šî”</param>
258- ''' <param name="uppercase">‘啶Žš‚©itruejA¬•¶Žš‚©ifalsej</param>
259- ''' <returns>”’l•¶Žš—ñ</returns>
260- Public Overloads Shared Function ToString(ByVal n As Long, ByVal radix As Integer, ByVal uppercase As Boolean) As String
261-
262- Return ToString(CType(n, ULong), radix, uppercase)
263-
264- End Function
265-
266- ''' <summary>
267- ''' UInt64Œ^‚̐”’l‚ð3`36i”‚̐”’l•¶Žš—ñ‚É•ÏŠ·‚µ‚Ü‚·B
268- ''' </summary>
269- ''' <remarks>
270- ''' ¦2^8^10^16i”‚́AConvert.ToStringƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
271- ''' ¦|•„†‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
272- ''' </remarks>
273- ''' <param name="n">”’l</param>
274- ''' <param name="radix">Šî”</param>
275- ''' <param name="uppercase">‘啶Žš‚©itruejA¬•¶Žš‚©ifalsej</param>
276- ''' <returns>”’l•¶Žš—ñ</returns>
277- Public Overloads Shared Function ToString(ByVal n As ULong, ByVal radix As Integer, ByVal uppercase As Boolean) As String
278-
279- ' ˆø”‚ðƒ`ƒFƒbƒN‚ð‚·‚é
280- CheckRadixArgument(radix)
281-
282- ' ”’l‚́u0v‚́A‚ǂ̐i”‚Å‚àu0v‚É‚È‚é
283- If n = 0 Then
284- Return "0"
285- End If
286-
287- Dim curValue As New StringBuilder(41) ' •ÏŠ·’†‚̐”’l•¶Žš—ñ
288- ' ¦UInt64.MaxValue‚̐”’l‚ð3i”‚Å•\Œ»‚·‚é‚Æ41‚¯‚½‚Å‚·B
289- Dim curDigit As ULong = n ' –¢ˆ—‚̐”’l
290-
291- ' ”’l‚ð‰ðÍ‚µ‚Đ”’l•¶Žš—ñ‚É•ÏŠ·‚·‚é
292- Dim digit As ULong ' ˆ—’†‚Ì1‚¯‚½‚̐”’l
293- Do
294- ' ˆê”Ô‰º‚Ì‚¯‚½‚̐”’l‚ðŽæ‚èo‚·
295- digit = curDigit Mod CType(radix, ULong)
296- ' Žæ‚èo‚µ‚½1‚¯‚½‚ðØ‚èŽÌ‚Ä‚é
297- curDigit = CType(curDigit / CType(radix, ULong), ULong)
298-
299- curValue.Insert(0, GetNumberFromDigit(CType(digit, Integer), uppercase))
300- Loop While curDigit <> 0
301-
302- Return curValue.ToString()
303-
304- End Function
305-
306-#End Region
307-
308-#Region "DecimalŒ^—p‚̃ƒ\ƒbƒhŒQ"
309-
310- ''' <summary>
311- ''' 3`36i”‚̐”’l•¶Žš—ñ‚ðDecimalŒ^‚̐”’l‚É•ÏŠ·‚µ‚Ü‚·B
312- ''' </summary>
313- ''' <remarks>
314- ''' ¦2^8^10^16i”‚́AConvert.ToDecimalƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
315- ''' ¦{‚â|‚Ì•„†‚â0x‚Ȃǂ̃vƒŒƒtƒBƒbƒNƒX‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
316- ''' ¦ˆø”‚ƂȂ鐔’l•¶Žš—ñ‚ɁAƒXƒy[ƒX‚È‚Ç‚Ì•¶Žš‚ðŠÜ‚ß‚È‚¢‚Å‚­‚¾‚³‚¢B
317- ''' </remarks>
318- ''' <param name="s">”’l•¶Žš—ñ</param>
319- ''' <param name="radix">Šî”</param>
320- ''' <returns>”’l</returns>
321- Public Shared Function ToDecimal(ByVal s As String, ByVal radix As Integer) As Decimal
322-
323- ' ˆø”‚ðƒ`ƒFƒbƒN‚ð‚·‚é
324- CheckNumberArgument(s)
325- CheckRadixArgument(radix)
326-
327- Dim curValue As Decimal = 0 ' •ÏŠ·’†‚̐”’l
328- Dim maxValue As Decimal = Decimal.MaxValue / CType(radix, Decimal) ' Å‘å’l‚Ì1‚¯‚½‘O‚̐”’l
329-
330- ' ”’l•¶Žš—ñ‚ð‰ðÍ‚µ‚Đ”’l‚É•ÏŠ·‚·‚é
331- Dim num As Char ' ˆ—’†‚Ì1‚¯‚½‚̐”’l•¶Žš—ñ
332- Dim digit As Integer ' ˆ—’†‚Ì1‚¯‚½‚̐”’l
333- Dim length As Integer = s.Length
334- For i As Integer = 0 To length - 1
335- num = s(i)
336- digit = GetDigitFromNumber(num)
337- CheckDigitOutOfRange(digit, radix)
338-
339- ' ŽŸ‚Éradix‚ðŠ|‚¯‚é‚Æ‚«‚ɐ”’l‚ªƒI[ƒo[ƒtƒ[‚µ‚È‚¢‚©‚ðŽ–‘O‚Ƀ`ƒFƒbƒN‚·‚é
340- CheckDigitOverflow(curValue, maxValue)
341- curValue = curValue * CType(radix, Decimal) + CType(digit, Decimal)
342- Next
343-
344- Return curValue
345-
346- End Function
347-
348- ''' <summary>
349- ''' DecimalŒ^‚̐”’l‚ð3`36i”‚̐”’l•¶Žš—ñ‚É•ÏŠ·‚µ‚Ü‚·B
350- ''' </summary>
351- ''' <remarks>
352- ''' ¦2^8^10^16i”‚́AConvert.ToStringƒƒ\ƒbƒh‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B
353- ''' ¦|•„†‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB
354- ''' </remarks>
355- ''' <param name="n">”’l</param>
356- ''' <param name="radix">Šî”</param>
357- ''' <param name="uppercase">‘啶Žš‚©itruejA¬•¶Žš‚©ifalsej</param>
358- ''' <returns>”’l•¶Žš—ñ</returns>
359- Public Overloads Shared Function ToString(ByVal n As Decimal, ByVal radix As Integer, ByVal uppercase As Boolean) As String
360-
361- ' ˆø”‚ðƒ`ƒFƒbƒN‚ð‚·‚é
362- CheckRadixArgument(radix)
363-
364- ' ”’l‚́u0v‚́A‚ǂ̐i”‚Å‚àu0v‚É‚È‚é
365- If n = 0 Then
366- Return "0"
367- End If
368-
369- Dim curValue As New StringBuilder(120) ' •ÏŠ·’†‚̐”’l•¶Žš—ñ
370- ' ¦Decimal.MaxValue‚̐”’l‚ð3i”‚Å•\Œ»‚·‚é‚Æ120‚¯‚½‚Å‚·B
371- Dim curDigit As Decimal = n ' –¢ˆ—‚̐”’l
372-
373- ' ”’l‚ð‰ðÍ‚µ‚Đ”’l•¶Žš—ñ‚É•ÏŠ·‚·‚é
374- Dim digit As Decimal ' ˆ—’†‚Ì1‚¯‚½‚̐”’l
375- Do
376- ' ˆê”Ô‰º‚Ì‚¯‚½‚̐”’l‚ðŽæ‚èo‚·
377- digit = curDigit Mod CType(radix, Decimal)
378- ' Žæ‚èo‚µ‚½1‚¯‚½‚ðØ‚èŽÌ‚Ä‚é
379- curDigit = curDigit / CType(radix, Decimal)
380-
381- curValue.Insert(0, GetNumberFromDigit(CType(digit, Integer), uppercase))
382- Loop While curDigit <> 0
383-
384- Return curValue.ToString()
385-
386- End Function
387-
388-#End Region
389-
390-#Region "“à•”‚ÅŽg—p‚µ‚Ä‚¢‚郁ƒ\ƒbƒhŒQ"
391-
392- Private Shared Sub CheckNumberArgument(ByVal s As String)
393-
394- If s = Nothing OrElse s = String.Empty Then
395- Throw New ArgumentException("”’l•¶Žš—ñ‚ªŽw’肳‚ê‚Ä‚¢‚Ü‚¹‚ñB")
396- End If
397-
398- End Sub
399-
400- Private Shared Sub CheckRadixArgument(ByVal radix As Integer)
401-
402- If radix = 2 OrElse radix = 8 OrElse radix = 10 OrElse radix = 16 Then
403- Throw New ArgumentException("2^8^10^16i”‚ÍSystem.ConvertƒNƒ‰ƒX‚ðŽg‚Á‚Ä‚­‚¾‚³‚¢B")
404- End If
405- If radix <= 1 OrElse 36 < radix Then
406- Throw New ArgumentException("3`36i”‚É‚µ‚©‘Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB")
407- End If
408-
409- End Sub
410-
411- Private Shared Sub CheckDigitOutOfRange(ByVal digit As Integer, ByVal radix As Integer)
412-
413- If digit < 0 OrElse radix <= digit Then
414- Throw New ArgumentOutOfRangeException("”’l‚ª”͈͊O‚Å‚·B")
415- End If
416-
417- End Sub
418-
419- Private Shared Sub CheckDigitOverflow(ByVal curValue As ULong, ByVal maxValue As ULong)
420-
421- If curValue > maxValue Then
422- Throw New OverflowException("”’l‚ªÅ‘å’l‚ð’´‚¦‚Ü‚µ‚½B")
423- End If
424-
425- End Sub
426-
427- Private Shared Sub CheckDigitOverflow(ByVal curValue As Decimal, ByVal maxValue As Decimal)
428-
429- If curValue > maxValue Then
430- Throw New OverflowException("”’l‚ªÅ‘å’l‚ð’´‚¦‚Ü‚µ‚½B")
431- End If
432-
433- End Sub
434-
435- Private Shared Function GetDigitFromNumber(ByVal num As Char) As Integer
436-
437- Dim ascNum As Integer = Asc(num)
438- If ascNum >= Asc("0") AndAlso ascNum <= Asc("9") Then
439- Return Asc(num) - Asc("0")
440- ElseIf ascNum >= Asc("A") AndAlso ascNum <= Asc("Z") Then
441- Return ascNum - Asc("A") + 10
442- ElseIf ascNum >= Asc("a") AndAlso ascNum <= Asc("z") Then
443- Return ascNum - Asc("a") + 10
444- Else
445- Return -1
446- End If
447-
448- End Function
449-
450- Private Shared Function GetNumberFromDigit(ByVal digit As Integer, ByVal uppercase As Boolean) As Char
451-
452- If digit < 10 Then
453- Return Chr(Asc("0") + digit)
454- ElseIf uppercase Then
455- Return Chr(Asc("A") + digit - 10)
456- Else
457- Return Chr(Asc("a") + digit - 10)
458- End If
459-
460- End Function
461-
462-#End Region
463-
464-End Class
465-
--- a/Tween/Tween.vbproj
+++ b/Tween/Tween.vbproj
@@ -213,7 +213,6 @@
213213 </Compile>
214214 <Compile Include="MySpecialPath.vb" />
215215 <Compile Include="nicoms.vb" />
216- <Compile Include="RadixConvert.vb" />
217216 <Compile Include="Setting\SettingAtIdList.vb" />
218217 <Compile Include="Setting\SettingLocal.vb" />
219218 <Compile Include="Setting\SettingFollower.vb" />
--- /dev/null
+++ b/TweenCS/RadixConvert.cs
@@ -0,0 +1,462 @@
1+// Tween - Client of Twitter
2+// Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3+// (c) 2008-2011 Moz (@syo68k)
4+// (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5+// (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6+// (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7+// (c) 2011 Egtra (@egtra) <http://dev.activebasic.com/egtra/>
8+// All rights reserved.
9+//
10+// This file is part of Tween.
11+//
12+// This program is free software; you can redistribute it and/or modify it
13+// under the terms of the GNU General Public License as published by the Free
14+// Software Foundation; either version 3 of the License, or (at your option)
15+// any later version.
16+//
17+// This program is distributed in the hope that it will be useful, but
18+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20+// for more details.
21+//
22+// You should have received a copy of the GNU General Public License along
23+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25+// Boston, MA 02110-1301, USA.
26+
27+using System;
28+using System.Collections.Generic;
29+using System.Linq;
30+using System.Text;
31+
32+namespace Tween
33+{
34+ public static class RadixConvert
35+ {
36+ #region "Int16型およびUInt16型用のメソッド群"
37+
38+ /// <summary>
39+ /// 3~36進数の数値文字列をInt16型の数値に変換します。
40+ /// </summary>
41+ /// <remarks>
42+ /// ※2/8/10/16進数は、Convert.ToInt16メソッドを使ってください。
43+ /// ※+や-の符号や0xなどのプレフィックスには対応していません。
44+ /// ※引数となる数値文字列に、スペースなどの文字を含めないでください。
45+ /// </remarks>
46+ /// <param name="s">数値文字列</param>
47+ /// <param name="radix">基数</param>
48+ /// <returns>数値</returns>
49+ public static short ToInt16(string s, int radix)
50+ {
51+ var digit = ToUInt64(s, radix);
52+ CheckDigitOverflow(digit, Int16.MaxValue);
53+ return (short)digit;
54+ }
55+
56+ /// <summary>
57+ /// 3~36進数の数値文字列をUInt16型の数値に変換します。
58+ /// </summary>
59+ /// <remarks>yy
60+ /// ※2/8/10/16進数は、Convert.ToUInt16メソッドを使ってください。
61+ /// ※+や-の符号や0xなどのプレフィックスには対応していません。
62+ /// ※引数となる数値文字列に、スペースなどの文字を含めないでください。
63+ /// </remarks>
64+ /// <param name="s">数値文字列</param>
65+ /// <param name="radix">基数</param>
66+ /// <returns>数値</returns>
67+ public static ushort ToUInt16(string s, int radix)
68+ {
69+ var digit = ToUInt64(s, radix);
70+ CheckDigitOverflow(digit, UInt16.MaxValue);
71+ return (ushort)digit;
72+ }
73+
74+ /// <summary>
75+ /// UInt16型の数値を3~36進数の数値文字列に変換します。
76+ /// </summary>
77+ /// <remarks>
78+ /// ※2/8/10/16進数は、Convert.Tostringメソッドを使ってください。
79+ /// ※-符号には対応していません。
80+ /// </remarks>
81+ /// <param name="n">数値</param>
82+ /// <param name="radix">基数</param>
83+ /// <param name="uppercase">大文字か(true)、小文字か(false)</param>
84+ /// <returns>数値文字列</returns>
85+ public static string ToString(short n, int radix, bool uppercase)
86+ {
87+ return ToString((ulong)n, radix, uppercase);
88+ }
89+
90+ /// <summary>
91+ /// UInt16型の数値を3~36進数の数値文字列に変換します。
92+ /// </summary>
93+ /// <remarks>
94+ /// ※2/8/10/16進数は、Convert.Tostringメソッドを使ってください。
95+ /// ※-符号には対応していません。
96+ /// </remarks>
97+ /// <param name="n">数値</param>
98+ /// <param name="radix">基数</param>
99+ /// <param name="uppercase">大文字か(true)、小文字か(false)</param>
100+ /// <returns>数値文字列</returns>
101+ public static string ToString(ushort n, int radix, bool uppercase)
102+ {
103+ return ToString((ulong)n, radix, uppercase);
104+ }
105+
106+ #endregion
107+
108+ #region "Int32型およびUInt32型用のメソッド群"
109+
110+ /// <summary>
111+ /// 3~36進数の数値文字列をInt32型の数値に変換します。
112+ /// </summary>
113+ /// <remarks>
114+ /// ※2/8/10/16進数は、Convert.ToInt32メソッドを使ってください。
115+ /// ※+や-の符号や0xなどのプレフィックスには対応していません。
116+ /// ※引数となる数値文字列に、スペースなどの文字を含めないでください。
117+ /// </remarks>
118+ /// <param name="s">数値文字列</param>
119+ /// <param name="radix">基数</param>
120+ /// <returns>数値</returns>
121+ public static int ToInt32(string s, int radix)
122+ {
123+ var digit = ToUInt64(s, radix);
124+ CheckDigitOverflow(digit, Int32.MaxValue);
125+ return (int)digit;
126+ }
127+
128+ /// <summary>
129+ /// 3~36進数の数値文字列をUInt32型の数値に変換します。
130+ /// </summary>
131+ /// <remarks>
132+ /// ※2/8/10/16進数は、Convert.ToUInt32メソッドを使ってください。
133+ /// ※+や-の符号や0xなどのプレフィックスには対応していません。
134+ /// ※引数となる数値文字列に、スペースなどの文字を含めないでください。
135+ /// </remarks>
136+ /// <param name="s">数値文字列</param>
137+ /// <param name="radix">基数</param>
138+ /// <returns>数値</returns>
139+ public static uint ToUInt32(string s, int radix)
140+ {
141+ var digit = ToUInt64(s, radix);
142+ CheckDigitOverflow(digit, UInt32.MaxValue);
143+ return (uint)digit;
144+ }
145+
146+ /// <summary>
147+ /// UInt32型の数値を3~36進数の数値文字列に変換します。
148+ /// </summary>
149+ /// <remarks>
150+ /// ※2/8/10/16進数は、Convert.Tostringメソッドを使ってください。
151+ /// ※-符号には対応していません。
152+ /// </remarks>
153+ /// <param name="n">数値</param>
154+ /// <param name="radix">基数</param>
155+ /// <param name="uppercase">大文字か(true)、小文字か(false)</param>
156+ /// <returns>数値文字列</returns>
157+ public static string ToString(int n, int radix, bool uppercase)
158+ {
159+ return ToString((ulong)n, radix, uppercase);
160+ }
161+
162+ /// <summary>
163+ /// UInt32型の数値を3~36進数の数値文字列に変換します。
164+ /// </summary>
165+ /// <remarks>
166+ /// ※2/8/10/16進数は、Convert.Tostringメソッドを使ってください。
167+ /// ※-符号には対応していません。
168+ /// </remarks>
169+ /// <param name="n">数値</param>
170+ /// <param name="radix">基数</param>
171+ /// <param name="uppercase">大文字か(true)、小文字か(false)</param>
172+ /// <returns>数値文字列</returns>
173+ public static string ToString(uint n, int radix, bool uppercase)
174+ {
175+ return ToString((ulong)n, radix, uppercase);
176+ }
177+
178+ #endregion
179+
180+ #region "Int64型およびUInt64型用のメソッド群"
181+
182+ /// <summary>
183+ /// 3~36進数の数値文字列をInt64型の数値に変換します。
184+ /// </summary>
185+ /// <remarks>
186+ /// ※2/8/10/16進数は、Convert.ToInt64メソッドを使ってください。
187+ /// ※+や-の符号や0xなどのプレフィックスには対応していません。
188+ /// ※引数となる数値文字列に、スペースなどの文字を含めないでください。
189+ /// </remarks>
190+ /// <param name="s">数値文字列</param>
191+ /// <param name="radix">基数</param>
192+ /// <returns>数値</returns>
193+ public static long ToInt64(string s, int radix)
194+ {
195+ var digit = ToUInt64(s, radix); ;
196+ CheckDigitOverflow(digit, Int64.MaxValue);
197+ return (long)digit;
198+ }
199+
200+ /// <summary>
201+ /// 3~36進数の数値文字列をUInt64型の数値に変換します。
202+ /// </summary>
203+ /// <remarks>
204+ /// ※2/8/10/16進数は、Convert.ToUInt64メソッドを使ってください。
205+ /// ※+や-の符号や0xなどのプレフィックスには対応していません。
206+ /// ※引数となる数値文字列に、スペースなどの文字を含めないでください。
207+ /// </remarks>
208+ /// <param name="s">数値文字列</param>
209+ /// <param name="radix">基数</param>
210+ /// <returns>数値</returns>
211+ public static ulong ToUInt64(string s, int radix)
212+ {
213+ // 引数をチェックをする
214+ CheckNumberArgument(s);
215+ CheckRadixArgument(radix);
216+
217+ var curValue = 0uL; // 変換中の数値
218+ var maxValue = UInt64.MaxValue / (ulong)radix; // 最大値の1けた前の数値
219+
220+ // 数値文字列を解析して数値に変換する
221+ char num; // 処理中の1けたの数値文字列
222+ int digit; // 処理中の1けたの数値
223+ int length = s.Length;
224+ for (int i = 0; i < length; i++)
225+ {
226+ num = s[i];
227+ digit = GetDigitFromNumber(num);
228+ CheckDigitOutOfRange(digit, radix);
229+
230+ // 次にradixを掛けるときに数値がオーバーフローしないかを事前にチェックする
231+ CheckDigitOverflow(curValue, maxValue);
232+ curValue = curValue * (ulong)radix + (ulong)digit;
233+ }
234+ return curValue;
235+ }
236+
237+ /// <summary>
238+ /// UInt64型の数値を3~36進数の数値文字列に変換します。
239+ /// </summary>
240+ /// <remarks>
241+ /// ※2/8/10/16進数は、Convert.Tostringメソッドを使ってください。
242+ /// ※-符号には対応していません。
243+ /// </remarks>
244+ /// <param name="n">数値</param>
245+ /// <param name="radix">基数</param>
246+ /// <param name="uppercase">大文字か(true)、小文字か(false)</param>
247+ /// <returns>数値文字列</returns>
248+ public static string ToString(long n, int radix, bool uppercase)
249+ {
250+ return ToString((ulong)n, radix, uppercase);
251+ }
252+
253+ /// <summary>
254+ /// UInt64型の数値を3~36進数の数値文字列に変換します。
255+ /// </summary>
256+ /// <remarks>
257+ /// ※2/8/10/16進数は、Convert.Tostringメソッドを使ってください。
258+ /// ※-符号には対応していません。
259+ /// </remarks>
260+ /// <param name="n">数値</param>
261+ /// <param name="radix">基数</param>
262+ /// <param name="uppercase">大文字か(true)、小文字か(false)</param>
263+ /// <returns>数値文字列</returns>
264+ public static string ToString(ulong n, int radix, bool uppercase)
265+ {
266+ // 引数をチェックをする
267+ CheckRadixArgument(radix);
268+
269+ // 数値の「0」は、どの進数でも「0」になる
270+ if (n == 0)
271+ {
272+ return "0";
273+ }
274+
275+ var curValue = new StringBuilder(41); // 変換中の数値文字列
276+ // ※UInt64.MaxValueの数値を3進数で表現すると41けたです。
277+ var curDigit = n; // 未処理の数値
278+
279+ // 数値を解析して数値文字列に変換する
280+ ulong digit; // 処理中の1けたの数値
281+ do
282+ {
283+ // 一番下のけたの数値を取り出す
284+ digit = curDigit % (ulong)radix;
285+ // 取り出した1けたを切り捨てる
286+ curDigit = curDigit / (ulong)radix;
287+
288+ curValue.Insert(0, GetNumberFromDigit((int)digit, uppercase));
289+ } while (curDigit != 0);
290+
291+ return curValue.ToString();
292+ }
293+
294+ #endregion
295+
296+ #region "Decimal型用のメソッド群"
297+
298+ /// <summary>
299+ /// 3~36進数の数値文字列をDecimal型の数値に変換します。
300+ /// </summary>
301+ /// <remarks>
302+ /// ※2/8/10/16進数は、Convert.ToDecimalメソッドを使ってください。
303+ /// ※+や-の符号や0xなどのプレフィックスには対応していません。
304+ /// ※引数となる数値文字列に、スペースなどの文字を含めないでください。
305+ /// </remarks>
306+ /// <param name="s">数値文字列</param>
307+ /// <param name="radix">基数</param>
308+ /// <returns>数値</returns>
309+ public static decimal ToDecimal(string s, int radix)
310+ {
311+ // 引数をチェックをする
312+ CheckNumberArgument(s);
313+ CheckRadixArgument(radix);
314+
315+ var curValue = 0m; // 変換中の数値
316+ decimal maxValue = decimal.MaxValue / (decimal)radix; // 最大値の1けた前の数値
317+
318+ // 数値文字列を解析して数値に変換する
319+ char num; // 処理中の1けたの数値文字列
320+ int digit; // 処理中の1けたの数値
321+ int length = s.Length;
322+ for (int i = 0; i < length; i++)
323+ {
324+ num = s[i];
325+ digit = GetDigitFromNumber(num);
326+ CheckDigitOutOfRange(digit, radix);
327+
328+ // 次にradixを掛けるときに数値がオーバーフローしないかを事前にチェックする
329+ CheckDigitOverflow(curValue, maxValue);
330+ curValue = curValue * (decimal)radix + (decimal)digit;
331+ }
332+ return curValue;
333+ }
334+
335+ /// <summary>
336+ /// Decimal型の数値を3~36進数の数値文字列に変換します。
337+ /// </summary>
338+ /// <remarks>
339+ /// ※2/8/10/16進数は、Convert.Tostringメソッドを使ってください。
340+ /// ※-符号には対応していません。
341+ /// </remarks>
342+ /// <param name="n">数値</param>
343+ /// <param name="radix">基数</param>
344+ /// <param name="uppercase">大文字か(true)、小文字か(false)</param>
345+ /// <returns>数値文字列</returns>
346+ public static string ToString(decimal n, int radix, bool uppercase)
347+ {
348+ // 引数をチェックをする
349+ CheckRadixArgument(radix);
350+
351+ // 数値の「0」は、どの進数でも「0」になる
352+ if (n == 0)
353+ {
354+ return "0";
355+ }
356+
357+ var curValue = new StringBuilder(120); // 変換中の数値文字列
358+ // ※Decimal.MaxValueの数値を3進数で表現すると120けたです。
359+ var curDigit = n; // 未処理の数値
360+
361+ // 数値を解析して数値文字列に変換する
362+ decimal digit; // 処理中の1けたの数値
363+ do
364+ {
365+ // 一番下のけたの数値を取り出す
366+ digit = curDigit % (decimal)radix;
367+ // 取り出した1けたを切り捨てる
368+ curDigit = curDigit / (decimal)radix;
369+
370+ curValue.Insert(0, GetNumberFromDigit((int)digit, uppercase));
371+ } while (curDigit != 0);
372+
373+ return curValue.ToString();
374+ }
375+
376+ #endregion
377+
378+ #region "内部で使用しているメソッド群"
379+
380+ private static void CheckNumberArgument(string s)
381+ {
382+ if (object.Equals(s, null) || object.Equals(s, string.Empty))
383+ {
384+ throw new ArgumentException("数値文字列が指定されていません。");
385+ }
386+ }
387+
388+ private static void CheckRadixArgument(int radix)
389+ {
390+ if (radix == 2 || radix == 8 || radix == 10 || radix == 16)
391+ {
392+ throw new ArgumentException("2/8/10/16進数はSystem.Convertクラスを使ってください。");
393+ }
394+ if (radix <= 1 || 36 < radix)
395+ {
396+ throw new ArgumentException("3~36進数にしか対応していません。");
397+ }
398+ }
399+
400+ private static void CheckDigitOutOfRange(int digit, int radix)
401+ {
402+ if (digit < 0 || radix <= digit)
403+ {
404+ throw new ArgumentOutOfRangeException("数値が範囲外です。");
405+ }
406+ }
407+
408+ private static void CheckDigitOverflow(ulong curValue, ulong maxValue)
409+ {
410+ if (curValue > maxValue)
411+ {
412+ throw new OverflowException("数値が最大値を超えました。");
413+ }
414+ }
415+
416+ private static void CheckDigitOverflow(decimal curValue, decimal maxValue)
417+ {
418+ if (curValue > maxValue)
419+ {
420+ throw new OverflowException("数値が最大値を超えました。");
421+ }
422+ }
423+
424+ private static int GetDigitFromNumber(char num)
425+ {
426+ var ascNum = num;
427+ if (ascNum >= '0' && ascNum <= '9')
428+ {
429+ return num - '0';
430+ }
431+ else if (ascNum >= 'A' && ascNum <= 'Z')
432+ {
433+ return ascNum - 'A' + 10;
434+ }
435+ else if (ascNum >= 'a' && ascNum <= 'z')
436+ {
437+ return ascNum - 'a' + 10;
438+ }
439+ else
440+ {
441+ return -1;
442+ }
443+ }
444+
445+ private static char GetNumberFromDigit(int digit, bool uppercase)
446+ {
447+ if (digit < 10)
448+ {
449+ return (char)('0' + digit);
450+ }
451+ else if (uppercase)
452+ {
453+ return (char)('A' + digit - 10);
454+ }
455+ else
456+ {
457+ return (char)('a' + digit - 10);
458+ }
459+ }
460+ #endregion
461+ }
462+}
--- a/TweenCS/TweenCS.csproj
+++ b/TweenCS/TweenCS.csproj
@@ -87,6 +87,7 @@
8787 <DesignTime>True</DesignTime>
8888 <DependentUpon>Resources.resx</DependentUpon>
8989 </Compile>
90+ <Compile Include="RadixConvert.cs" />
9091 <Compile Include="SearchWord.cs">
9192 <SubType>Form</SubType>
9293 </Compile>