Go

package
v0.3.38 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GoReservedKeywords is a list of Go reserved keywords.
	GoReservedKeywords []string
)

Functions

func FixVarNameIncremental

func FixVarNameIncremental(variable_name string, keywords []string, min int, start int) (string, bool)

FixVarNameIncremental works like FixVariableName but it appends an incremental number to the variable name instead of a suffix.

Parameters:

  • variable_name: The variable name to fix.
  • keywords: The list of keywords to check against.
  • min: The minimum length of the variable name. If less than 1, the function uses 1.
  • start: The starting number to append to the variable name. If less than 0, the function uses 0.

Returns:

  • string: The fixed variable name.
  • bool: True if the variable name is not empty. False otherwise.

func FixVariableName

func FixVariableName(variable_name string, keywords []string, min int, suffix string) (string, bool)

FixVariableName fixes the given variable name by checking whether or not the name trimmed to the minimum length is valid. If it is not valid, the function appends the given suffix to the name until a valid name is found.

Moreover, if the name is greater than the minimum length, the function first checks whether the name can be trimmed to the minimum length and still be valid. If it is not valid, the function tries the remaining characters one by one until a valid name is found. Finally, if it is still not valid, the function appends the given suffix to the name until a valid name is found.

Parameters:

  • variable_name: The variable name to fix.
  • keywords: The list of keywords to check against.
  • min: The minimum length of the variable name. If less than 1, the function uses 1.
  • suffix: The suffix to append to the variable name. If empty, the function uses "_".

Returns:

  • string: The fixed variable name.
  • bool: True if the variable name is not empty. False otherwise.

func IsGenericsID

func IsGenericsID(str string) (rune, error)

IsGenericsID checks if the input string is a valid single upper case letter and returns it as a rune.

Parameters:

  • str: The input string to check.

Returns:

  • rune: The valid single upper case letter.
  • error: An error if the input string is not a valid single upper case letter.

func IsValidName

func IsValidName(variable_name string, keywords []string) bool

IsValidName checks if the given variable name is valid.

This function checks if the variable name is not empty and if it is not a Go reserved keyword. It also checks if the variable name is not in the list of keywords.

Parameters:

  • variable_name: The variable name to check.
  • keywords: The list of keywords to check against.

Returns:

  • bool: True if the variable name is valid. False otherwise.

func MakeVariableName

func MakeVariableName(type_name string) (string, error)

MakeVariableName converts a type name to a variable name.

Parameters:

  • type_name: The type name to convert.

Returns:

  • string: The variable name.
  • error: An error if the type name is invalid.

Errors:

  • *common.ErrInvalidParameter: If the type name is empty.
  • *common.ErrAt: If the type name is invalid at a specific position.

func ParseFields

func ParseFields(str string) (map[string]string, error)

ParseFields parses the given string to extract fields and their types.

Parameters:

  • str: The string containing fields to parse.

Returns:

  • map[string]string: A map of field names to their corresponding types.
  • error: An error if parsing encounters any issues.

func ParseGenerics

func ParseGenerics(str string) ([]rune, error)

ParseGenerics parses a string representing a list of generic types enclosed in square brackets.

Parameters:

  • str: The string to parse.

Return types:

  • []rune: An array of runes representing the parsed generic types.
  • error: An error if the parsing fails.

Types

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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