0 people like it.

deserialising php's serialise

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
module php =
  let deserialise (str : string) = 
    let gs (s : string) (k : int) = 
      try
      let b = s.IndexOf(":", k) + 1
      let e = s.IndexOf(":", b)
      let l = System.Int32.Parse(s.Substring(b, e - b))
      s.Substring(e + 2, l)

      with | ex -> ""
      
    let sn i = str.[i - 1]
    
    let ex (k,s) = 
     
      match (k,s) with
      | (_,':') -> 
        match sn k with
        | 's' -> gs str k
        | _ -> ""
      | (_,'N') -> 
        match sn k with
        | ';' -> "No value"
        |  _  -> ""
      | _ -> ""
      
    seq { 
        for i=0 to str.Length - 1 do yield i, str.[i] 
    }   |> Seq.map ex
        |> Seq.filter ((<>) "")
val deserialise : str:string -> seq<string>

Full name: Script.php.deserialise
val str : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val gs : (string -> int -> string)
val s : string
val k : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val b : int
System.String.IndexOf(value: string) : int
System.String.IndexOf(value: char) : int
System.String.IndexOf(value: string, comparisonType: System.StringComparison) : int
System.String.IndexOf(value: string, startIndex: int) : int
System.String.IndexOf(value: char, startIndex: int) : int
System.String.IndexOf(value: string, startIndex: int, comparisonType: System.StringComparison) : int
System.String.IndexOf(value: string, startIndex: int, count: int) : int
System.String.IndexOf(value: char, startIndex: int, count: int) : int
System.String.IndexOf(value: string, startIndex: int, count: int, comparisonType: System.StringComparison) : int
val e : int
val l : int
namespace System
type Int32 =
  struct
    member CompareTo : value:obj -> int + 1 overload
    member Equals : obj:obj -> bool + 1 overload
    member GetHashCode : unit -> int
    member GetTypeCode : unit -> TypeCode
    member ToString : unit -> string + 3 overloads
    static val MaxValue : int
    static val MinValue : int
    static member Parse : s:string -> int + 3 overloads
    static member TryParse : s:string * result:int -> bool + 1 overload
  end

Full name: System.Int32
System.Int32.Parse(s: string) : int
System.Int32.Parse(s: string, provider: System.IFormatProvider) : int
System.Int32.Parse(s: string, style: System.Globalization.NumberStyles) : int
System.Int32.Parse(s: string, style: System.Globalization.NumberStyles, provider: System.IFormatProvider) : int
System.String.Substring(startIndex: int) : string
System.String.Substring(startIndex: int, length: int) : string
val ex : exn
val sn : (int -> char)
val i : int
val ex : (int * char -> string)
val s : char
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
property System.String.Length: int
module Seq

from Microsoft.FSharp.Collections
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
val filter : predicate:('T -> bool) -> source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.filter
Raw view Test code New version

More information

Link:http://fssnip.net/az
Posted:14 years ago
Author:
Tags: