2023-04-22 21:16:22 +03:00
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package templates
2023-04-29 15:02:29 +03:00
import (
2024-03-01 10:11:51 +03:00
"fmt"
"html/template"
2023-04-29 15:02:29 +03:00
"strings"
"code.gitea.io/gitea/modules/base"
)
2023-04-22 21:16:22 +03:00
type StringUtils struct { }
2023-04-29 15:02:29 +03:00
var stringUtils = StringUtils { }
2023-04-22 21:16:22 +03:00
func NewStringUtils ( ) * StringUtils {
2023-04-29 15:02:29 +03:00
return & stringUtils
2023-04-22 21:16:22 +03:00
}
2024-03-01 10:11:51 +03:00
func ( su * StringUtils ) ToString ( v any ) string {
switch v := v . ( type ) {
case string :
return v
case template . HTML :
return string ( v )
case fmt . Stringer :
return v . String ( )
default :
return fmt . Sprint ( v )
}
}
2023-04-22 21:16:22 +03:00
func ( su * StringUtils ) HasPrefix ( s , prefix string ) bool {
return strings . HasPrefix ( s , prefix )
}
func ( su * StringUtils ) Contains ( s , substr string ) bool {
return strings . Contains ( s , substr )
}
2023-04-29 00:23:19 +03:00
func ( su * StringUtils ) Split ( s , sep string ) [ ] string {
return strings . Split ( s , sep )
}
2023-04-29 15:02:29 +03:00
func ( su * StringUtils ) Join ( a [ ] string , sep string ) string {
return strings . Join ( a , sep )
}
2023-09-03 04:43:29 +03:00
func ( su * StringUtils ) Cut ( s , sep string ) [ ] any {
before , after , found := strings . Cut ( s , sep )
return [ ] any { before , after , found }
}
2024-12-15 05:31:07 +03:00
func ( su * StringUtils ) EllipsisString ( s string , maxLength int ) string {
return base . EllipsisString ( s , maxLength )
2023-04-29 15:02:29 +03:00
}
2024-01-19 19:05:02 +03:00
func ( su * StringUtils ) ToUpper ( s string ) string {
return strings . ToUpper ( s )
}
Do not display `attestation-manifest` and use short sha256 instead of full sha256 (#32851)
Related: #24973
Before:
![image](https://github.com/user-attachments/assets/bca17900-5075-4d15-af7a-c71bf8979c04)
After:
![image](https://github.com/user-attachments/assets/c5a24e3b-763b-4463-80db-d4dbd89f7dc4)
Index:
```json
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.index.v1+json",
"manifests": [
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:5967afffdfde104ca1459286a72346baaef8b70ac153325d7a6cd85c7734ac6e",
"size": 672,
"platform": {
"architecture": "amd64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:f9abfcc55320f9ff1f38eeb7dbb4bea10b29c7febfa49ccd7aab9fa02403b9f0",
"size": 672,
"platform": {
"architecture": "arm64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:d70ad19d00c19e40691045cbddc3e8a5a4454c31cc454d1132b13bcaf35b6d46",
"size": 566,
"annotations": {
"vnd.docker.reference.digest": "sha256:5967afffdfde104ca1459286a72346baaef8b70ac153325d7a6cd85c7734ac6e",
"vnd.docker.reference.type": "attestation-manifest"
},
"platform": {
"architecture": "unknown",
"os": "unknown"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:73bc233bf4eac96a404ce3e0430b698831a4ea7050c878d5f76d1d1f133751dd",
"size": 566,
"annotations": {
"vnd.docker.reference.digest": "sha256:f9abfcc55320f9ff1f38eeb7dbb4bea10b29c7febfa49ccd7aab9fa02403b9f0",
"vnd.docker.reference.type": "attestation-manifest"
},
"platform": {
"architecture": "unknown",
"os": "unknown"
}
}
]
}
```
---------
Co-authored-by: silverwind <me@silverwind.io>
2024-12-16 05:22:49 +03:00
func ( su * StringUtils ) TrimPrefix ( s , prefix string ) string {
return strings . TrimPrefix ( s , prefix )
}