Author: rolf
Date: 2007-05-30 10:38:01 -0400 (Wed, 30 May 2007)
New Revision: 78220
Modified:
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/ChangeLog
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Collection.vb
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/DateAndTime.vb
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Information.vb
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Strings.vb
Log:
* DateAndTime.vb: Move OS-specific code to the OS drivers (date/time
setters). Fix DateAdd to use the current culture.
* Information.vb: Speed up IsNumeric and make it equal to
Versioned.IsNumeric (except where it's supposed to be different).
* Strings.vb: Speed up Filter, and provide an implementation for Asc
for non-ascii code pages.
* Collection.vb: On any profile below 2.0 the IList.Item setter is
broken, so break it.
Modified:
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/ChangeLog
===================================================================
---
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/ChangeLog
2007-05-30 14:37:37 UTC (rev 78219)
+++
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/ChangeLog
2007-05-30 14:38:01 UTC (rev 78220)
@@ -1,3 +1,14 @@
+2007-05-30 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
+
+ * DateAndTime.vb: Move OS-specific code to the OS drivers (date/time
+ setters). Fix DateAdd to use the current culture.
+ * Information.vb: Speed up IsNumeric and make it equal to
+ Versioned.IsNumeric (except where it's supposed to be different).
+ * Strings.vb: Speed up Filter, and provide an implementation for Asc
+ for non-ascii code pages.
+ * Collection.vb: On any profile below 2.0 the IList.Item setter is
+ broken, so break it.
+
2007-05-21 Eyal Alaluf <[EMAIL PROTECTED]>
* DateAndTime.vb: Fix DateDiff of DateInterval.WeekOfYear
Modified:
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Collection.vb
===================================================================
---
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Collection.vb
2007-05-30 14:37:37 UTC (rev 78219)
+++
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Collection.vb
2007-05-30 14:38:01 UTC (rev 78220)
@@ -60,6 +60,10 @@
Private m_KeysCount As Integer = Integer.MinValue
Friend Modified As Boolean = False
+#If NET_VER < 2.0 Then
+ Private m_Broken As Boolean
+#End If
+
Private Class ColEnumerator
Implements IEnumerator
@@ -235,6 +239,9 @@
Private Property IList_Item(ByVal index As Integer) As Object
Implements System.Collections.IList.Item
Get
+#If NET_VER < 2.0 Then
+ If m_Broken Then Throw New InvalidCastException ()
+#End If
If index < 0 AndAlso Count > 0 Then
'Oh man this behaviour is weird...
index = 0
@@ -248,7 +255,9 @@
End Get
Set(ByVal Value As Object)
-
+#If NET_VER < 2.0 Then
+ m_Broken = True
+#End If
If index < 0 AndAlso Count > 0 Then
'Oh man this behaviour is weird...
index = 0
Modified:
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/DateAndTime.vb
===================================================================
---
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/DateAndTime.vb
2007-05-30 14:37:37 UTC (rev 78219)
+++
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/DateAndTime.vb
2007-05-30 14:38:01 UTC (rev 78220)
@@ -52,39 +52,19 @@
DateTimeFormatInfo.CurrentInfo, _
DateTimeStyles.None)
- Today = dtToday
+ OSSpecific.OSDriver.Driver.SetDate(dtToday)
Catch e As FormatException
Throw New InvalidCastException(String.Format("Cast from
string {0} to type 'Date' is not valid.", Value))
End Try
End Set
End Property
-#If TARGET_JVM = False Then
- <DllImport("libc", EntryPoint:="stime", _
- SetLastError:=True, CharSet:=CharSet.Unicode, _
- ExactSpelling:=True, _
- CallingConvention:=CallingConvention.StdCall)> _
- Friend Function stime(ByVal t As Integer) As Integer
- ' Leave function empty - DllImport attribute forwards calls to
stime to
- ' stime in libc.dll
- End Function
-#End If
Public Property Today() As System.DateTime
Get
Return DateTime.Today
End Get
Set(ByVal Value As System.DateTime)
- Dim Now As System.DateTime = DateTime.Now
- Dim NewDate As System.DateTime = New DateTime(Value.Year,
Value.Month, Value.Day, _
- Now.Hour, Now.Minute,
Now.Second, Now.Millisecond)
- Dim secondsTimeSpan As System.TimeSpan =
NewDate.ToUniversalTime().Subtract(New DateTime(1970, 1, 1, 0, 0, 0))
- Dim seconds As Integer = CType(secondsTimeSpan.TotalSeconds,
Integer)
-
-#If TARGET_JVM = False And disabled Then
- If (stime(seconds) = -1) Then
- Throw New UnauthorizedAccessException("The caller is not
the super-user.")
- End If
-#End If
+ OSSpecific.OSDriver.Driver.SetDate(Value)
End Set
End Property
@@ -112,18 +92,7 @@
TSpan.Milliseconds)
End Get
Set(ByVal Value As System.DateTime)
- Today = DateTime.Now
- Dim NewTime As System.DateTime = New DateTime(Today.Year,
Today.Month, Today.Day, _
- Value.Hour,
Value.Minute, Value.Second)
-
- Dim secondsTimeSpan As TimeSpan =
NewTime.ToUniversalTime().Subtract(New DateTime(1970, 1, 1, 0, 0, 0, 0))
- Dim seconds As Integer = CType(secondsTimeSpan.TotalSeconds,
Integer)
-
-#If TARGET_JVM = False And disabled Then
- If (stime(seconds) = -1) Then
- Throw New UnauthorizedAccessException("The caller is not
the super-user.")
- End If
-#End If
+ OSSpecific.OSDriver.Driver.SetTime(Value)
End Set
End Property
@@ -132,14 +101,14 @@
Return DateTime.Now.ToString("HH:mm:ss")
End Get
Set(ByVal Value As String)
- Dim formats() As String = {"HH:mm:ss", "H:mm:ss", "h:mm:ss",
"hh:mm:ss", "H:mm:ss tt", "h:mm:ss t", "hh:mm", "hh:mm tt", "h:mm", "h:mm tt",
"h:m", "h:m tt"}
+ Dim formats() As String = {"hh:mm:ss tt", "H:mm:ss tt",
"HH:mm:ss", "H:mm:ss", "h:mm:ss", "hh:mm:ss", "hh:mm", "hh:mm tt", "h:mm",
"h:mm tt", "h:m", "h:m tt"}
Try
Dim dtToday As DateTime = DateTime.ParseExact(Value,
formats, _
DateTimeFormatInfo.CurrentInfo, _
DateTimeStyles.None)
- TimeOfDay = dtToday
+ OSSpecific.OSDriver.Driver.SetTime(dtToday)
Catch e As FormatException
Throw New InvalidCastException(String.Format("Cast from
string {0} to type '{1}' is not valid.", Value, "Date"))
End Try
@@ -149,24 +118,27 @@
' Methods
Public Function DateAdd(ByVal Interval As DateInterval, _
ByVal Number As Double, ByVal DateValue As System.DateTime) As
System.DateTime
+ Dim value As Integer
+ value = CInt(Conversion.Fix(Number))
+
Select Case Interval
Case DateInterval.Year
- Return DateValue.AddYears(CType(Number, Integer))
+ Return
Threading.Thread.CurrentThread.CurrentCulture.Calendar.AddYears(DateValue,
value)
Case DateInterval.Quarter
- Return DateValue.AddMonths(CType((Number * 3), Integer))
+ Return
Threading.Thread.CurrentThread.CurrentCulture.Calendar.AddMonths(DateValue,
value * 3)
Case DateInterval.Month
- Return DateValue.AddMonths(CType(Number, Integer))
+ Return
Threading.Thread.CurrentThread.CurrentCulture.Calendar.AddMonths(DateValue,
value)
Case DateInterval.WeekOfYear
- Return DateValue.AddDays(Number * 7)
+ Return
Threading.Thread.CurrentThread.CurrentCulture.Calendar.AddDays(DateValue, value
* 7)
Case DateInterval.Day, DateInterval.DayOfYear,
DateInterval.Weekday
- Return DateValue.AddDays(Number)
+ Return
Threading.Thread.CurrentThread.CurrentCulture.Calendar.AddDays(DateValue, value)
Case DateInterval.Hour
- Return DateValue.AddHours(Number)
+ Return
Threading.Thread.CurrentThread.CurrentCulture.Calendar.AddHours(DateValue,
value)
Case DateInterval.Minute
- Return DateValue.AddMinutes(Number)
+ Return
Threading.Thread.CurrentThread.CurrentCulture.Calendar.AddMinutes(DateValue,
value)
Case DateInterval.Second
- Return DateValue.AddSeconds(Number)
+ Return
Threading.Thread.CurrentThread.CurrentCulture.Calendar.AddSeconds(DateValue,
value)
Case Else
Throw New ArgumentException
End Select
@@ -498,7 +470,7 @@
Dim d As DateTime = DateTime.Parse(StringDate, _
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat,
DateTimeStyles.NoCurrentDateDefault)
- Return d.Subtract(d.TimeOfDay)
+ Return d.Date
Catch exception As FormatException
Throw New InvalidCastException(String.Format("Cast from string
{0} to type '{1}' is not valid.", StringDate, "Date"))
End Try
Modified:
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Information.vb
===================================================================
---
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Information.vb
2007-05-30 14:37:37 UTC (rev 78219)
+++
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Information.vb
2007-05-30 14:38:01 UTC (rev 78220)
@@ -96,20 +96,22 @@
End Function
Public Function IsNumeric(ByVal Expression As Object) As Boolean
- If (Expression Is Nothing) Or (TypeOf Expression Is Date) Then
Return False
+ If Expression Is Nothing Then Return False
- If (TypeOf Expression Is Short) Or (TypeOf Expression Is Integer)
Or (TypeOf Expression Is Long) _
- Or (TypeOf Expression Is Decimal) Or (TypeOf Expression Is
Single) Or (TypeOf Expression Is Double) _
- Or (TypeOf Expression Is Boolean) Or (TypeOf Expression Is
Byte) Then Return True
-
- Try
- If TypeOf Expression Is String Then
- Convert.ToDouble(Expression)
+ Select Case Type.GetTypeCode(Expression.GetType)
+ Case TypeCode.Byte, TypeCode.Int16, TypeCode.Int32,
TypeCode.Int64, TypeCode.Double, TypeCode.Single, TypeCode.Decimal,
TypeCode.Boolean
Return True
- End If
- Catch ex As Exception
- Return False
- End Try
+ Case TypeCode.UInt16, TypeCode.UInt32, TypeCode.UInt64,
TypeCode.SByte
+ Return False
+ Case TypeCode.DateTime
+ Return False
+ Case TypeCode.String
+ Return Double.TryParse(DirectCast(Expression, String), 0)
+ Case TypeCode.Char
+ Return Double.TryParse(DirectCast(Expression, Char), 0)
+ Case Else
+ Return False
+ End Select
Return False
End Function
Modified:
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Strings.vb
===================================================================
---
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Strings.vb
2007-05-30 14:37:37 UTC (rev 78219)
+++
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic/Strings.vb
2007-05-30 14:38:01 UTC (rev 78220)
@@ -77,8 +77,12 @@
End Sub
Public Function Asc(ByVal c As Char) As Integer
- 'FIXME : provide an implementation for non-ASCII chars
- Return Convert.ToInt32(c)
+ Dim enc As System.Text.Encoding
+ enc =
System.Text.Encoding.GetEncoding(Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ANSICodePage)
+
+ Dim bytes() As Byte
+ bytes = enc.GetBytes(New Char() {c})
+ Return bytes(0)
End Function
Public Function AscW(ByVal c As Char) As Integer
@@ -145,7 +149,7 @@
Public Function Filter(ByVal Source() As Object, ByVal Match As
String, Optional ByVal Include As Boolean = True, _
<OptionCompare()> Optional ByVal Compare As
CompareMethod = CompareMethod.Binary) As String()
- Dim Temp(Source.Length) As String
+ Dim Temp(Source.Length-1) As String
If Compare = CompareMethod.Text Then
Match = Match.ToLower
@@ -161,20 +165,15 @@
Dim comparisonResult As Boolean = (s.IndexOf(Match) >= 0)
- If (comparisonResult And Include) Or (Not comparisonResult And
Not Include) Then
+ If comparisonResult = Include Then
Temp(j) = CStr(Source(i))
j = j + 1
End If
Next
- Dim Res(j - 1) As String
- For i As Integer = 0 To j - 1
- Res(i) = Temp(i)
- Next
- ' FIXME : use redim
- 'ReDim Preserve Temp(j - 1)
+ ReDim Preserve Temp(j - 1)
- Return Res
+ Return Temp
End Function
Public Function Filter(ByVal Source() As String, ByVal Match As
String, Optional ByVal Include As Boolean = True, _
@@ -219,9 +218,11 @@
If Not PredefinedStyle Is Nothing Then
Return String.Format(PredefinedStyle.ToString(), Expression)
End If
-
- Return String.Format("{0:" + Style + "}", Expression)
-
+ If Style = "" Then
+ Return String.Format("{0}", Expression)
+ Else
+ Return String.Format("{0:" + Style + "}", Expression)
+ End If
End Function
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches