Skip to content

Instantly share code, notes, and snippets.

@locatw
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save locatw/ece1ded34e21af3829b6 to your computer and use it in GitHub Desktop.

Select an option

Save locatw/ece1ded34e21af3829b6 to your computer and use it in GitHub Desktop.
Replace "&-" to "&" in byte list in F#. This is used for IMAP-UTF7 decoding.
let replaceAmpersandHyphenToAmpersand (input : byte list) =
let replacedTail =
input
|> List.windowed 2
|> List.choose (fun chunk -> match chunk with
// 0x26 : '&', 0x2d : '-'
| [a; b] when a = (byte)0x26 && b = (byte)0x2d -> None
| [_; b] -> Some(b)
| _ -> failwith "invalid chunk")
input.Head :: replacedTail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment