snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped

This commit is contained in:
upstream-mirror
2026-09-15 21:19:12 +05:00
commit c60cc7ca75
8092 changed files with 394160 additions and 0 deletions

26
oryx/stringsx/case.go Normal file
View File

@@ -0,0 +1,26 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package stringsx
import "unicode"
// ToLowerInitial converts a string's first character to lower case.
func ToLowerInitial(s string) string {
if s == "" {
return ""
}
a := []rune(s)
a[0] = unicode.ToLower(a[0])
return string(a)
}
// ToUpperInitial converts a string's first character to upper case.
func ToUpperInitial(s string) string {
if s == "" {
return ""
}
a := []rune(s)
a[0] = unicode.ToUpper(a[0])
return string(a)
}

16
oryx/stringsx/split.go Normal file
View File

@@ -0,0 +1,16 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package stringsx
import "strings"
// Splitx is a special case of strings.Split
// which returns an empty slice if the string is empty
func Splitx(s, sep string) []string {
if s == "" {
return []string{}
}
return strings.Split(s, sep)
}

View File

@@ -0,0 +1,90 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package stringsx
import (
"fmt"
"slices"
"strings"
)
type (
RegisteredCases struct {
cases []string
actual string
}
errUnknownCase struct {
*RegisteredCases
}
RegisteredPrefixes struct {
prefixes []string
actual string
}
errUnknownPrefix struct {
*RegisteredPrefixes
}
)
var (
ErrUnknownCase = errUnknownCase{}
ErrUnknownPrefix = errUnknownPrefix{}
)
func SwitchExact(actual string) *RegisteredCases {
return &RegisteredCases{
actual: actual,
}
}
func SwitchPrefix(actual string) *RegisteredPrefixes {
return &RegisteredPrefixes{
actual: actual,
}
}
func (r *RegisteredCases) AddCase(cases ...string) bool {
r.cases = append(r.cases, cases...)
return slices.Contains(cases, r.actual)
}
func (r *RegisteredPrefixes) HasPrefix(prefixes ...string) bool {
r.prefixes = append(r.prefixes, prefixes...)
return slices.ContainsFunc(prefixes, func(s string) bool {
return strings.HasPrefix(r.actual, s)
})
}
func (r *RegisteredCases) String() string {
return "[" + strings.Join(r.cases, ", ") + "]"
}
func (r *RegisteredPrefixes) String() string {
return "[" + strings.Join(r.prefixes, ", ") + "]"
}
func (r *RegisteredCases) ToUnknownCaseErr() error {
return errUnknownCase{r}
}
func (r *RegisteredPrefixes) ToUnknownPrefixErr() error {
return errUnknownPrefix{r}
}
func (e errUnknownCase) Error() string {
return fmt.Sprintf("expected one of %s but got %s", e.String(), e.actual)
}
func (e errUnknownCase) Is(err error) bool {
_, ok := err.(errUnknownCase)
return ok
}
func (e errUnknownPrefix) Error() string {
return fmt.Sprintf("expected %s to have one of the prefixes %s", e.actual, e.String())
}
func (e errUnknownPrefix) Is(err error) bool {
_, ok := err.(errUnknownPrefix)
return ok
}

21
oryx/stringsx/truncate.go Normal file
View File

@@ -0,0 +1,21 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package stringsx
import "unicode/utf8"
// TruncateByteLen returns string truncated at the end with the length specified
func TruncateByteLen(s string, length int) string {
if length <= 0 || len(s) <= length {
return s
}
res := s[:length]
// in case we cut in the middle of an utf8 rune, we have to remove the last byte as well until it fits
for !utf8.ValidString(res) {
res = res[:len(res)-1]
}
return res
}