@@ -6,8 +6,6 @@ namespace Internal.Utilities
66// shims for things not yet implemented in Fable
77//------------------------------------------------------------------------
88
9- //TODO: implement proper Unicode char, decimal
10-
119module System =
1210
1311 module Decimal =
@@ -41,12 +39,14 @@ module System =
4139 module Concurrent =
4240 open System.Collections .Generic
4341
44- type ConcurrentDictionary < 'TKey , 'TValue when 'TKey: equality > =
45- inherit Dictionary< 'TKey, 'TValue>
46- new () = { inherit Dictionary< 'TKey, 'TValue>() }
47- new ( comparer : IEqualityComparer < 'TKey >) = { inherit Dictionary< 'TKey, 'TValue>( comparer) }
42+ type ConcurrentDictionary < 'TKey , 'TValue when 'TKey: equality >( comparer : IEqualityComparer < 'TKey >) =
43+ inherit Dictionary< 'TKey, 'TValue>( comparer)
44+ new () = ConcurrentDictionary {
45+ new IEqualityComparer< 'TKey> with
46+ member __.GetHashCode ( x ) = x.GetHashCode()
47+ member __.Equals ( x , y ) = x.Equals( y) }
4848 member x.TryAdd ( key : 'TKey , value : 'TValue ) = x.[ key] <- value; true
49- member x.GetOrAdd ( key , valueFactory ) =
49+ member x.GetOrAdd ( key : 'TKey , valueFactory : 'TKey -> 'TValue ): 'TValue =
5050 match x.TryGetValue key with
5151 | true , v -> v
5252 | false , _ -> let v = valueFactory( key) in x.[ key] <- v; v
@@ -107,168 +107,14 @@ module System =
107107 let normPath = path.Replace( " \\ " , " /" ) .TrimEnd( '/' )
108108 path.StartsWith( " /" )
109109
110- module Char =
111- open System.Globalization
112-
113- let GetUnicodeCategory ( c : char ): UnicodeCategory = //TODO: proper Unicode implementation
114- LanguagePrimitives.EnumOfValue ( int categoryForLatin1.[ int c])
115- let IsControl ( c : char ) =
116- GetUnicodeCategory( c) = UnicodeCategory.Control
117- let IsDigit ( c : char ) =
118- GetUnicodeCategory( c) = UnicodeCategory.DecimalDigitNumber
119- let IsLetter ( c : char ) =
120- match GetUnicodeCategory( c) with
121- | UnicodeCategory.UppercaseLetter
122- | UnicodeCategory.LowercaseLetter
123- | UnicodeCategory.TitlecaseLetter
124- | UnicodeCategory.ModifierLetter
125- | UnicodeCategory.OtherLetter -> true
126- | _ -> false
127- let IsLetterOrDigit ( c : char ) =
128- IsLetter( c) || IsDigit( c)
129- let IsWhiteSpace ( c : char ) =
130- // There are characters which belong to UnicodeCategory.Control but are considered as white spaces.
131- c = ' ' || ( c >= '\x09' && c <= '\x0d') || c = '\xa0' || c = '\x85'
132- let IsUpper ( c : char ) =
133- GetUnicodeCategory( c) = UnicodeCategory.UppercaseLetter
134- let IsLower ( c : char ) =
135- GetUnicodeCategory( c) = UnicodeCategory.LowercaseLetter
136- let IsPunctuation ( c : char ) =
137- match GetUnicodeCategory( c) with
138- | UnicodeCategory.ConnectorPunctuation
139- | UnicodeCategory.DashPunctuation
140- | UnicodeCategory.OpenPunctuation
141- | UnicodeCategory.ClosePunctuation
142- | UnicodeCategory.InitialQuotePunctuation
143- | UnicodeCategory.FinalQuotePunctuation
144- | UnicodeCategory.OtherPunctuation -> true
145- | _ -> false
146- let IsSurrogatePair ( s , i ) = false //TODO: proper Unicode implementation
147- let ToUpper ( c : char ) = if IsLower( c) then char( int( 'A' ) + ( int( c) - int( 'a' ))) else c
148- let ToLower ( c : char ) = if IsUpper( c) then char( int( 'a' ) + ( int( c) - int( 'A' ))) else c
149- let ToUpperInvariant ( c : char ) = ToUpper( c)
150- let ToLowerInvariant ( c : char ) = ToLower( c)
151- let ToString ( c : char ) = string c
152-
153- module Text =
154-
155- type StringBuilder (? s : string ) =
156- let buf = ResizeArray< string>()
157- do if Option.isSome s then buf.Add( s.Value)
158- new ( capacity : int , ? maxCapacity : int ) = StringBuilder()
159- new ( s : string , ? maxCapacity : int ) = StringBuilder( s)
160- member x.Append ( s : string ) = buf.Add( s); x
161- member x.AppendFormat ( fmt : string , o : obj ) = buf.Add( System.String.Format( fmt, o)); x
162- override x.ToString () = System.String.Concat( buf)
163-
164- module Encoding =
165-
166- module Unicode = // TODO: add surrogate pairs
167- let GetBytes ( s : string ) =
168- let addUnicodeChar ( buf : ResizeArray < byte >) ( c : char ) =
169- let i = int c
170- buf.Add ( byte ( i % 256 ))
171- buf.Add ( byte ( i / 256 ))
172- let buf = ResizeArray< byte>()
173- s.ToCharArray() |> Array.map ( addUnicodeChar buf) |> ignore
174- buf.ToArray()
175-
176- let GetString ( bytes : byte [], index : int , count : int ) =
177- let sb = StringBuilder()
178- for i in 0 .. 2 .. count-1 do
179- let c = char (( int( bytes.[ index+ i+ 1 ]) <<< 8 ) ||| int( bytes.[ index+ i]))
180- sb.Append( string c) |> ignore
181- sb.ToString()
182-
183- module UTF8 = // TODO: add surrogate pairs
184- let GetBytes ( s : string ) =
185- let buf = ResizeArray< byte>()
186- let encodeUtf8 ( c : char ) =
187- let i = int c
188- if i < 0x80 then
189- buf.Add ( byte( i))
190- else if i < 0x800 then
191- buf.Add ( byte( 0xC0 ||| ( i >>> 6 &&& 0x1F )))
192- buf.Add ( byte( 0x80 ||| ( i &&& 0x3F )))
193- else if i < 0x10000 then
194- buf.Add ( byte( 0xE0 ||| ( i >>> 12 &&& 0xF )))
195- buf.Add ( byte( 0x80 ||| ( i >>> 6 &&& 0x3F )))
196- buf.Add ( byte( 0x80 ||| ( i &&& 0x3F )))
197- s.ToCharArray() |> Array.map encodeUtf8 |> ignore
198- buf.ToArray()
199-
200- let GetString ( bytes : byte [], index : int , count : int ) =
201- let decodeUtf8 pos =
202- let i1 = int( bytes.[ pos])
203- if i1 &&& 0x80 = 0 then
204- ( i1 &&& 0x7F ), 1
205- else if i1 &&& 0xE0 = 0xC0 then
206- let i2 = int( bytes.[ pos + 1 ]) in
207- (( i1 &&& 0x1F ) <<< 6 ) ||| ( i2 &&& 0x3F ), 2
208- else if i1 &&& 0xF0 = 0xE0 then
209- let i2 = int( bytes.[ pos + 1 ]) in
210- let i3 = int( bytes.[ pos + 2 ]) in
211- (( i1 &&& 0x1F ) <<< 12 ) ||| (( i2 &&& 0x3F ) <<< 6 ) ||| ( i3 &&& 0x3F ), 3
212- else 0 , 1 // invalid decoding
213- let sb = StringBuilder()
214- let mutable pos = index
215- let last = index + count
216- while pos < last do
217- let d , inc = decodeUtf8 pos
218- sb.Append( string ( char d)) |> ignore
219- pos <- pos + inc
220- sb.ToString()
221-
222110
223111module Microsoft =
224112 module FSharp =
225113
226- module Collections =
227- open System.Collections .Generic
228-
229- module HashIdentity =
230- let inline FromFunctions hash eq : IEqualityComparer < 'T > =
231- { new IEqualityComparer< 'T> with
232- member __.GetHashCode ( x ) = hash x
233- member __.Equals ( x , y ) = eq x y }
234- let inline Structural < 'T when 'T : equality > : IEqualityComparer < 'T > =
235- FromFunctions LanguagePrimitives.GenericHash LanguagePrimitives.GenericEquality
236- let Reference < 'T when 'T : not struct > : IEqualityComparer < 'T > =
237- FromFunctions LanguagePrimitives.PhysicalHash LanguagePrimitives.PhysicalEquality
238-
239- module ComparisonIdentity =
240- let inline FromFunction comparer =
241- { new IComparer< 'T> with
242- member __.Compare ( x , y ) = comparer x y }
243- let inline Structural < 'T when 'T : comparison > : IComparer < 'T > =
244- FromFunction LanguagePrimitives.GenericComparison
245-
246- module List =
247- let indexed source = List.mapi ( fun i x -> i, x) source
248-
114+ //------------------------------------------------------------------------
115+ // From reshapedreflection.fs
116+ //------------------------------------------------------------------------
249117 module Core =
250- module LanguagePrimitives =
251- let FastGenericComparer < 'T when 'T : comparison > =
252- Collections.ComparisonIdentity.Structural< 'T>
253-
254- module Operators =
255- let (| Failure | _ |) ( exn : exn ) = Some exn.Message
256- //if exn.GetType().FullName.EndsWith("Exception") then Some exn.Message else None
257- let Failure message = new System.Exception( message)
258- let nullArg x = raise( System.ArgumentNullException( x))
259- let lock _lockObj action = action() // no locking
260-
261- module Printf =
262- let bprintf ( sb : System.Text.StringBuilder ) =
263- let f ( s : string ) = sb.Append( s) |> ignore
264- Printf.kprintf f
265- let fprintf ( os : System.IO.TextWriter ) =
266- let f ( s : string ) = System.Console.Write( s) //os.Write(s)
267- Printf.kprintf f
268-
269- //------------------------------------------------------------------------
270- // From reshapedreflection.fs
271- //------------------------------------------------------------------------
272118 module XmlAdapters =
273119 let s_escapeChars = [| '<' ; '>' ; '\"' ; '\'' ; '&' |]
274120 let getEscapeSequence c =
@@ -286,23 +132,24 @@ module Microsoft =
286132 //------------------------------------------------------------------------
287133 module Compiler =
288134 module SR =
289- let GetString ( name : string ) =
290- let ok , value = SR.Resources.resources.TryGetValue( name)
291- if ok then value
292- else " Missing FSStrings error message for: " + name
135+ let GetString ( name : string ) =
136+ match SR.Resources.resources.TryGetValue( name) with
137+ | true , value -> value
138+ | _ -> " Missing FSStrings error message for: " + name
293139
294- module internal DiagnosticMessage =
140+ module DiagnosticMessage =
295141 type ResourceString < 'T >( sfmt : string , fmt : string ) =
296142 member x.Format =
297- let ar = fmt.Split( '%' )
143+ let a = fmt.Split( '%' )
298144 |> Array.filter ( fun s -> String.length s > 0 )
299- |> Array.map ( fun s -> box( " %" + s))
300- let tmp = System.String.Format( sfmt, ar )
145+ |> Array.map ( fun s -> box( " %" + s))
146+ let tmp = System.String.Format( sfmt, a )
301147 let fmt = Printf.StringFormat< 'T>( tmp)
302148 sprintf fmt
303149
304- let postProcessString ( s : string ) =
150+ let postProcessString ( s : string ) =
305151 s.Replace( " \\ n" , " \n " ) .Replace( " \\ t" , " \t " )
306- let DeclareResourceString (( messageID : string ),( fmt : string )) =
152+
153+ let DeclareResourceString ( messageID : string , fmt : string ) =
307154 let messageString = SR.GetString( messageID) |> postProcessString
308155 ResourceString< 'T>( messageString, fmt)
0 commit comments