Sha256: 7e12b6cc2bc9ea7d9f23232b2ea27ed1dd03d5455ced62f21561532f29352b6e

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

package internal

import (
  "fmt"
  "github.com/iancoleman/strcase"
  "os"
  "regexp"
  "strings"
)

func LogMsg(msg string, args ...any) {
	fmt.Fprintf(os.Stderr, fmt.Sprintf(msg, args...))
	fmt.Fprintln(os.Stderr)
}

func FilePathify(s string) string {
	var result []string
	s = strings.Trim(s, ".")
	tokens := strings.Split(s, ".")
	for _, token := range tokens {
		result = append(result, strcase.ToSnake(token))
	}
	return strings.Join(result, "/")
}

func Classify(s string) string {
	var result []string
	s = strings.Trim(s, ".")
	tokens := strings.Split(s, ".")
	for _, token := range tokens {
		result = append(result, strcase.ToCamel(token))
	}
	return strings.Join(result, "::")
}

func Demodulize(s string) string {
	tokens := strings.Split(s, ".")
	return tokens[len(tokens)-1]
}

func SanitizePath(s string) string {
  re := regexp.MustCompile("\\{(.*?)}")
	matches := re.FindAllStringSubmatch(s, -1)
	for _, match := range matches {
		repl := match[1]
		equal := strings.Index(match[1], "=")
		if equal != -1 {
			repl = repl[0:equal]
		}
		dot := strings.Index(repl, ".")
		if dot != -1 {
			repl = repl[dot+1:]
		}
		s = strings.Replace(s, match[0], ":"+repl, 1)
	}
  return s
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grpc-rest-0.1.5 protoc-gen-rails/internal/utils.go
grpc-rest-0.1.4 protoc-gen-rails/internal/utils.go
grpc-rest-0.1.2 protoc-gen-rails/internal/utils.go
grpc-rest-0.1.1 protoc-gen-rails/internal/utils.go
grpc-rest-0.1.0 protoc-gen-rails/internal/utils.go