Skip to content

Instantly share code, notes, and snippets.

@NigelThorne
Created July 9, 2009 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NigelThorne/143346 to your computer and use it in GitHub Desktop.
Save NigelThorne/143346 to your computer and use it in GitHub Desktop.
Helper macro to be used with StoryQ
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module Module1
Sub StoryQConvert()
Dim textSelection As String
DTE.UndoContext.Open("StoryQConvert")
textSelection = DTE.ActiveDocument.Selection.Text
If (textSelection.Trim.StartsWith("""")) Then
StringToLambda()
Else
LambdaToString()
End If
DTE.UndoContext.Close()
End Sub
Sub StringToLambda()
Dim textSelection As TextSelection
Dim output As String
Dim capitalizeNext As Boolean
textSelection = DTE.ActiveDocument.Selection
capitalizeNext = True
For Each character In textSelection.Text
If (character = " " Or character = """") Then
capitalizeNext = True
Else
If capitalizeNext Then
output = output + Char.ToUpper(character)
capitalizeNext = False
Else
output = output + character
End If
End If
Next
textSelection.Text = "() => " + output + "()"
End Sub
Sub LambdaToString()
Dim textSelection As TextSelection
Dim output As String
textSelection = DTE.ActiveDocument.Selection
For Each character In textSelection.Text
If ("() =>".Contains(character)) Then
Continue For
End If
If (Char.ToUpper(character) = character) Then
output = output + " "
End If
output = output + Char.ToLower(character)
Next
textSelection.Text = """" + output.TrimStart + """"
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment