utils#

import "github.com/magnus-ffcg/go-dbt2lookml/pkg/utils"

Package utils provides utility functions for string manipulation and pointer helpers.

This package contains reusable utility functions used throughout the application for common operations like string transformation, sanitization, and pointer creation.

String Utilities:

  • CamelToSnake: Converts CamelCase to snake_case (handles acronyms correctly)
  • SnakeToCamel: Converts snake_case to CamelCase
  • ToLookMLName: Converts column names to LookML-compatible identifiers
  • SanitizeIdentifier: Removes invalid characters from identifiers
  • QuoteColumnNameIfNeeded: Adds backticks for names requiring quoting

Pointer Helpers:

  • StringPtr, BoolPtr, IntPtr, Int64Ptr, Float64Ptr: Create pointers to literal values

String Manipulation:

  • TruncateString: Safely truncate strings to maximum length
  • Pluralize: Simple English pluralization
  • ToTitleCase: Convert to title case

The package uses pre-compiled regular expressions for optimal performance in frequently-called string transformation functions.

Index#

func BoolPtr#

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to the given bool value. This is a convenience function to avoid creating intermediate variables.

func CamelToSnake#

func CamelToSnake(s string) string

CamelToSnake converts CamelCase to snake_case Handles complex cases like SupplierInformation -> supplier_information, GTINId -> gtin_id

func ContainsAny#

func ContainsAny(s string, substrings []string) bool

ContainsAny checks if a string contains any of the given substrings

func Float64Ptr#

func Float64Ptr(f float64) *float64

Float64Ptr returns a pointer to the given float64 value. This is a convenience function to avoid creating intermediate variables.

func Int64Ptr#

func Int64Ptr(i int64) *int64

Int64Ptr returns a pointer to the given int64 value. This is a convenience function to avoid creating intermediate variables.

func IntPtr#

func IntPtr(i int) *int

IntPtr returns a pointer to the given int value. This is a convenience function to avoid creating intermediate variables.

func IsEmpty#

func IsEmpty(s string) bool

IsEmpty checks if a string is empty or contains only whitespace

func JoinNonEmpty#

func JoinNonEmpty(parts []string, delimiter string) string

JoinNonEmpty joins non-empty strings with a delimiter

func Pluralize#

func Pluralize(word string) string

Pluralize adds ’s’ to a word (simple pluralization)

func QuoteColumnNameIfNeeded#

func QuoteColumnNameIfNeeded(columnName string) string

QuoteColumnNameIfNeeded adds backticks around column names that need quoting

func RemovePrefix#

func RemovePrefix(s, prefix string) string

RemovePrefix removes a prefix from a string if it exists

func RemoveSuffix#

func RemoveSuffix(s, suffix string) string

RemoveSuffix removes a suffix from a string if it exists

func SanitizeIdentifier#

func SanitizeIdentifier(s string) string

SanitizeIdentifier removes or replaces invalid characters from identifiers

func SnakeToCamel#

func SnakeToCamel(s string) string

SnakeToCamel converts snake_case to CamelCase

func SplitAndTrim#

func SplitAndTrim(s, delimiter string) []string

SplitAndTrim splits a string by delimiter and trims whitespace from each part

func StringPtr#

func StringPtr(s string) *string

StringPtr returns a pointer to the given string value. This is a convenience function to avoid creating intermediate variables.

func ToLookMLName#

func ToLookMLName(s string) string

ToLookMLName converts a column name to LookML naming convention. Converts PascalCase to snake_case and replaces dots with double underscores.

Note: This function expects proper PascalCase or camelCase input. If your column names are already lowercase (e.g., “supplierinformation”), they will remain as-is since there’s no case information to work with. Ensure your source data maintains proper case conventions (e.g., “SupplierInformation”) for correct conversion.

func ToTitleCase#

func ToTitleCase(s string) string

ToTitleCase converts a string to Title Case

func TruncateString#

func TruncateString(s string, maxLength int) string

TruncateString truncates a string to a maximum length

Generated by gomarkdoc