strings

package
v0.4.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2023 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommentDict = map[Language]CommentDelimiters{
	GoLang:     {Line, "", "", "//"},
	C:          {Block, "/*", "*/", "//"},
	CPP:        {Block, "/*", "*/", "//"},
	Java:       {Block, "/*", "*/", "//"},
	Python:     {Line, "", "", "#"},
	JavaScript: {Block, "/*", "*/", "//"},
	Ruby:       {Line, "", "", "#"},

	Perl:         {Line, "", "", "#"},
	Shell:        {Line, "", "", "#"},
	PHP:          {Block, "/*", "*/", "//"},
	Swift:        {Block, "/*", "*/", "//"},
	Rust:         {Block, "/*", "*/", "//"},
	Haskell:      {Line, "", "", "--"},
	HTML:         {Block, "<!--", "-->", ""},
	XML:          {Block, "<!--", "-->", ""},
	CSS:          {Block, "/*", "*/", ""},
	SQL:          {Line, "", "", "--"},
	R:            {Line, "", "", "#"},
	Scala:        {Block, "/*", "*/", "//"},
	Kotlin:       {Block, "/*", "*/", "//"},
	TypeScript:   {Block, "/*", "*/", "//"},
	Matlab:       {Block, "%{", "%}", "%"},
	Assembly:     {Line, "", "", ";"},
	Lua:          {Block, "--[[", "--]]", "--"},
	Fortran:      {Line, "", "", "!"},
	Bash:         {Line, "", "", "#"},
	Groovy:       {Block, "/*", "*/", "//"},
	Prolog:       {Line, "", "", "%"},
	YAML:         {Line, "", "", "#"},
	Markdown:     {Line, "", "", "//"},
	Dart:         {Block, "/*", "*/", "//"},
	CoffeeScript: {Line, "", "", "#"},
	FSharp:       {Line, "", "", "//"},
	Pascal:       {Block, "{", "}", ""},
	Lisp:         {Line, "", "", ";;"},
	Erlang:       {Block, "%{", "%}", "%"},
	Elixir:       {Line, "", "", "#"},
	HCL:          {Line, "", "", "#"},
}

CommentDict holds the delimiters for each supported language

Functions

func Float64SliceToStringSlice

func Float64SliceToStringSlice(list []float64) []string

func GenerateComment added in v0.4.17

func GenerateComment(comment string, language Language) string

GenerateComment converts a given string into a comment based on the specified programming language.

**Usage**: Call this function with a string and a language to get the string formatted as a comment in that language. For example: `comment := GenerateComment("TODO: Implement this", GoLang)`.

**Inner Workings**: The function uses the CommentDict map to determine the appropriate comment delimiters for the provided language. It then formats the string as a block or inline comment based on the language's conventions.

func IntSliceToStringSlice

func IntSliceToStringSlice(list []int) []string

func InterfaceListToStringList

func InterfaceListToStringList(list []interface{}) []string

func InterfaceToStringList

func InterfaceToStringList(list interface{}) []string

func StringInSlice

func StringInSlice(needle string, haystack []string) bool

func ToAlphaString

func ToAlphaString(n int) string

func UniqueStrings added in v0.2.84

func UniqueStrings(s []string) []string

Types

type CommentDelimiters added in v0.4.17

type CommentDelimiters struct {
	Type   CommentType
	Start  string
	End    string
	Inline string
}

CommentDelimiters represents the delimiters for each language

type CommentType added in v0.4.17

type CommentType int

CommentType represents the type of comment (block or line)

const (
	Block CommentType = iota
	Line
)

type Language added in v0.4.17

type Language string

Language represents the supported languages

const (
	GoLang       Language = "Go"
	C            Language = "C"
	CPP          Language = "C++"
	Java         Language = "Java"
	Python       Language = "Python"
	JavaScript   Language = "JavaScript"
	Ruby         Language = "Ruby"
	Perl         Language = "Perl"
	Shell        Language = "Shell"
	PHP          Language = "PHP"
	Swift        Language = "Swift"
	Rust         Language = "Rust"
	Haskell      Language = "Haskell"
	HTML         Language = "HTML"
	XML          Language = "XML"
	CSS          Language = "CSS"
	SQL          Language = "SQL"
	R            Language = "Language"
	Scala        Language = "Scala"
	Kotlin       Language = "Kotlin"
	TypeScript   Language = "TypeScript"
	Matlab       Language = "Matlab"
	Assembly     Language = "Assembly"
	Lua          Language = "Lua"
	Fortran      Language = "Fortran"
	Bash         Language = "Bash"
	Groovy       Language = "Groovy"
	Prolog       Language = "Prolog"
	YAML         Language = "YAML"
	Markdown     Language = "Markdown"
	Dart         Language = "Dart"
	CoffeeScript Language = "CoffeeScript"
	FSharp       Language = "FSharp"
	Pascal       Language = "Pascal"
	Lisp         Language = "Lisp"
	Erlang       Language = "Erlang"
	Elixir       Language = "Elixir"
	HCL          Language = "HCL"
)
const (
	None Language = "None"
)

func MarkdownCodeBlockToLanguage added in v0.4.17

func MarkdownCodeBlockToLanguage(codeBlock string) Language

MarkdownCodeBlockToLanguage translates a markdown code block language specifier to its corresponding Language type.

**Usage**: Use this function to identify the language of a code block in markdown. For example, given the string "py", the function will return the Python constant.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL