corregido el formateador de error para que no escriba la seccion Causes en caso de que no tenga ninguna
parent
4b14eff493
commit
38177ccf76
@ -0,0 +1,71 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name active.go
|
||||
// Created by DEV
|
||||
// Modified 21/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package cjson
|
||||
|
||||
import "unicode/utf8"
|
||||
|
||||
var (
|
||||
|
||||
G = struct {
|
||||
Hex string
|
||||
JSONChars [utf8.RuneSelf]CharAtt
|
||||
|
||||
NullValue []byte
|
||||
ZeroValue []byte
|
||||
TrueValue []byte
|
||||
FalseValue []byte
|
||||
|
||||
FloatNaN []byte
|
||||
FloatInfPos []byte
|
||||
FloatInfNeg []byte
|
||||
} {
|
||||
|
||||
Hex: "0123456789abcdef",
|
||||
JSONChars: initJSONChars(),
|
||||
|
||||
NullValue: []byte{'n', 'u', 'l', 'l'},
|
||||
ZeroValue: []byte{'0'},
|
||||
TrueValue: []byte{'"','t', 'r', 'u', 'e','"'},
|
||||
FalseValue: []byte{'"','f', 'a', 'l', 's', 'e','"'},
|
||||
|
||||
FloatNaN: []byte{'"', 'N', 'a', 'N', '"'},
|
||||
FloatInfPos: []byte{'"', 'I', 'n', 'f', '"'},
|
||||
FloatInfNeg: []byte{'"', '-', 'I', 'n', 'f', '"'},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
func initJSONChars() [utf8.RuneSelf]CharAtt {
|
||||
var tb = [utf8.RuneSelf]CharAtt{
|
||||
'"': CharAttAllUnsafe,
|
||||
'&': CharAttHtmlUnsafe,
|
||||
'<': CharAttHtmlUnsafe,
|
||||
'>': CharAttHtmlUnsafe,
|
||||
'\\': CharAttAllUnsafe,
|
||||
}
|
||||
for i := 0; i <= 31; i++ {
|
||||
tb[i] = CharAttAllUnsafe
|
||||
}
|
||||
return tb
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name char_att.go
|
||||
// Created by DEV
|
||||
// Modified 21/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package cjson
|
||||
|
||||
|
||||
const (
|
||||
CharAttUnsafe CharAtt = 1 << iota
|
||||
CharAttHtmlUnsafe
|
||||
|
||||
CharAttAllUnsafe = CharAttUnsafe | CharAttHtmlUnsafe
|
||||
)
|
||||
|
||||
type CharAtt uint8
|
||||
|
||||
|
||||
|
||||
func (a CharAtt) IsUnsafe() bool {
|
||||
return a&CharAttUnsafe != 0 }
|
||||
|
||||
func (a CharAtt) IsHtmlUnsafe() bool {
|
||||
return a&CharAttHtmlUnsafe != 0 }
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,257 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name writer.go
|
||||
// Created by DEV
|
||||
// Modified 21/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package cjson
|
||||
|
||||
import (
|
||||
"bins/bfers"
|
||||
"encoding/base32"
|
||||
"encoding/base64"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
|
||||
func WriteString(b *bfers.Buffer, value string, escapeHTML bool ) {
|
||||
if len(value) == 0 {
|
||||
b.Write2Byte('"', '"')
|
||||
return
|
||||
}
|
||||
|
||||
b.WriteByte('"')
|
||||
start := 0
|
||||
for i := 0; i < len(value); {
|
||||
if ch := value[i]; ch < utf8.RuneSelf {
|
||||
|
||||
if !G.JSONChars[ch].IsHtmlUnsafe() || (!escapeHTML && !G.JSONChars[ch].IsUnsafe()) {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
if start < i {
|
||||
b.WriteString(value[start:i])
|
||||
}
|
||||
b.WriteByte('\\')
|
||||
switch ch {
|
||||
case '\\', '"':
|
||||
b.WriteByte(ch)
|
||||
case '\n':
|
||||
b.WriteByte('n')
|
||||
case '\r':
|
||||
b.WriteByte('r')
|
||||
case '\t':
|
||||
b.WriteByte('t')
|
||||
default:
|
||||
b.WriteString(`u00`)
|
||||
b.Write2Byte(G.Hex[ch>>4], G.Hex[ch&0xF])
|
||||
}
|
||||
i++
|
||||
start = i
|
||||
continue
|
||||
}
|
||||
c, size := utf8.DecodeRuneInString(value[i:])
|
||||
if c == utf8.RuneError && size == 1 {
|
||||
if start < i {
|
||||
b.WriteString(value[start:i])
|
||||
}
|
||||
b.WriteString(`\ufffd`)
|
||||
i += size
|
||||
start = i
|
||||
continue
|
||||
}
|
||||
|
||||
if c == '\u2028' || c == '\u2029' {
|
||||
if start < i {
|
||||
b.WriteString(value[start:i])
|
||||
}
|
||||
b.WriteString(`\u202`)
|
||||
b.WriteByte(G.Hex[c&0xF])
|
||||
i += size
|
||||
start = i
|
||||
continue
|
||||
}
|
||||
i += size
|
||||
}
|
||||
if start < len(value) {
|
||||
b.WriteString(value[start:])
|
||||
}
|
||||
b.WriteByte('"')
|
||||
}
|
||||
|
||||
|
||||
|
||||
func WriteUint (b *bfers.Buffer, value uint64 , quoted bool) {
|
||||
if quoted {
|
||||
b.WriteByte('"')
|
||||
}
|
||||
if value == 0 {
|
||||
b.WriteByte('0')
|
||||
} else {
|
||||
b.WriteUIntStr(value, 10)
|
||||
}
|
||||
if quoted {
|
||||
b.WriteByte('"')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func WriteBool (b *bfers.Buffer, value bool , quoted bool) {
|
||||
if value {
|
||||
b.WOQ(quoted,'"', G.TrueValue)
|
||||
} else {
|
||||
b.WOQ(quoted,'"', G.FalseValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func WriteInt (b *bfers.Buffer, value int64 , quoted bool) {
|
||||
if quoted {
|
||||
b.WriteByte('"')
|
||||
}
|
||||
if value == 0 {
|
||||
b.WriteByte('0')
|
||||
} else {
|
||||
b.WriteIntStr(value, 10)
|
||||
}
|
||||
if quoted {
|
||||
b.WriteByte('"')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func WriteFloat (b *bfers.Buffer, f float64, bits int, quoted bool) {
|
||||
var t [64]byte
|
||||
if math.IsInf(f, 0) || math.IsNaN(f) {
|
||||
_,_ = b.Write(G.FloatNaN)
|
||||
return
|
||||
}
|
||||
|
||||
abs := math.Abs(f)
|
||||
fm := byte('f')
|
||||
|
||||
if abs != 0 {
|
||||
if bits == 64 && (abs < 1e-6 || abs >= 1e21) || bits == 32 && (float32(abs) < 1e-6 || float32(abs) >= 1e21) {
|
||||
fm = 'e'
|
||||
}
|
||||
}
|
||||
bf := t[:0]
|
||||
bf = strconv.AppendFloat(bf, f, fm, -1, int(bits))
|
||||
if fm == 'e' {
|
||||
// clean up e-09 to e-9
|
||||
n := len(bf)
|
||||
if n >= 4 && bf[n-4] == 'e' && bf[n-3] == '-' && bf[n-2] == '0' {
|
||||
bf[n-2] = bf[n-1]
|
||||
bf = bf[:n-1]
|
||||
}
|
||||
}
|
||||
|
||||
b.WOQ(quoted,'"',bf)
|
||||
}
|
||||
|
||||
|
||||
func WriteDate(b *bfers.Buffer, value time.Time, layout string) {
|
||||
var t [64]byte
|
||||
if layout == "" {
|
||||
layout = time.RFC3339
|
||||
}
|
||||
b.WOQ(true,'"',value.AppendFormat(t[:0],layout))
|
||||
}
|
||||
|
||||
|
||||
func WriteBinary64 (b *bfers.Buffer, value []byte) (er error) {
|
||||
if value == nil {
|
||||
_,_ = b.Write(G.NullValue)
|
||||
return nil
|
||||
}
|
||||
if len(value) == 0 {
|
||||
b.Write2Byte('"','"')
|
||||
return nil
|
||||
}
|
||||
|
||||
p := b.Len()
|
||||
b.WriteByte('"')
|
||||
|
||||
var t [64]byte
|
||||
ln := base64.StdEncoding.EncodedLen(len(value))
|
||||
if ln <= len(t) {
|
||||
dst := t[:ln]
|
||||
base64.StdEncoding.Encode(dst, value)
|
||||
_,er = b.Write(dst)
|
||||
} else if ln <= 1024 {
|
||||
dst := make([]byte, ln)
|
||||
base64.StdEncoding.Encode(dst, value)
|
||||
_,er = b.Write(dst)
|
||||
} else if er == nil {
|
||||
ec := base64.NewEncoder(base64.StdEncoding, b)
|
||||
_,_ = ec.Write(value)
|
||||
er = ec.Close()
|
||||
}
|
||||
|
||||
if er == nil {
|
||||
b.WriteByte('"')
|
||||
} else {
|
||||
b.Truncate(p)
|
||||
}
|
||||
|
||||
return er
|
||||
}
|
||||
|
||||
func WriteBinary32 (b *bfers.Buffer, value []byte) (er error) {
|
||||
if value == nil {
|
||||
_,_ = b.Write(G.NullValue)
|
||||
return nil
|
||||
}
|
||||
if len(value) == 0 {
|
||||
b.Write2Byte('"','"')
|
||||
return nil
|
||||
}
|
||||
|
||||
p := b.Len()
|
||||
b.WriteByte('"')
|
||||
|
||||
var t [64]byte
|
||||
|
||||
ln := base32.StdEncoding.EncodedLen(len(value))
|
||||
if ln <= len(t) {
|
||||
dst := t[:ln]
|
||||
base32.StdEncoding.Encode(dst, value)
|
||||
_,er = b.Write(dst)
|
||||
} else if ln <= 1024 {
|
||||
dst := make([]byte, ln)
|
||||
base32.StdEncoding.Encode(dst, value)
|
||||
_,er = b.Write(dst)
|
||||
} else if er == nil {
|
||||
ec := base32.NewEncoder(base32.StdEncoding, b)
|
||||
_,_ = ec.Write(value)
|
||||
return ec.Close()
|
||||
}
|
||||
|
||||
if er == nil {
|
||||
b.WriteByte('"')
|
||||
} else {
|
||||
b.Truncate(p)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
module cdcs
|
||||
|
||||
go 1.22
|
||||
@ -0,0 +1,50 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name Layout.go
|
||||
// Created by DEV
|
||||
// Modified 13/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package fjson
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
Layout struct {
|
||||
Indent string
|
||||
TimeLayout string
|
||||
DateLayout string
|
||||
}
|
||||
|
||||
LayoutFnc func (layouts *Layout)
|
||||
)
|
||||
|
||||
|
||||
|
||||
func newLayout () *Layout {
|
||||
return &Layout{
|
||||
Indent: " ",
|
||||
DateLayout: time.RFC3339,
|
||||
TimeLayout: time.TimeOnly,
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name active.go
|
||||
// Created by DEV
|
||||
// Modified 22/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package ftext
|
||||
|
||||
import (
|
||||
"errs/stack"
|
||||
)
|
||||
|
||||
func defaultFrameBuilder (builder *TextBuilder, frame stack.Frame, num int) {
|
||||
/*
|
||||
if strings.Index(frame.Package,"runtime") != -1 {
|
||||
return
|
||||
}
|
||||
|
||||
var c1, c2, c3, c4 ansi.Code
|
||||
if builder.Options().ShowAnsi(){
|
||||
c1 = c1.SetFgColor(ansi.ColorBlue)//.SetBgColor(ansi.ColorHBlack)
|
||||
c2 = c2.SetFgColor(ansi.ColorMagenta)
|
||||
c3 = c3.SetFgColor(ansi.ColorWhite)
|
||||
c4 = c3.SetFgColor(ansi.ColorHWhite)
|
||||
}
|
||||
|
||||
builder.AddText(c4.Sprintf(" %d %s.%s \n",num,frame.Package, frame.FuncName))
|
||||
builder.AddText(c2.Sprintf(" %.90s:%d\n", frame.File, frame.LineNumber))
|
||||
|
||||
f, e := frame.SourceLine()
|
||||
if e == nil {
|
||||
builder.AddTextAnsi(fmt.Sprintf(" %s\n", f),c3)
|
||||
} else {
|
||||
builder.AddTextAnsi(fmt.Sprintf(" error %s\n", e.Error()),c3)
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
func defaultFallback (b *TextBuilder, err, cause error) {
|
||||
/*
|
||||
b.AddText(fmt.Sprintf("Formatter error: Cant format error type (%s)\nValue : %#v \nCause : %s\n",reflect.TypeOf(err).String(),err,cause.Error()))
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name fallback.go
|
||||
// Created by DEV
|
||||
// Modified 18/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package ftext
|
||||
|
||||
|
||||
type (
|
||||
|
||||
|
||||
ErrorFallbackFnc func (builder *TextBuilder, err, cause error)
|
||||
)
|
||||
@ -0,0 +1,61 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name Layout.go
|
||||
// Created by DEV
|
||||
// Modified 13/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package ftext
|
||||
|
||||
import (
|
||||
"ansi"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
Layout struct {
|
||||
AnsiC ansi.Code
|
||||
Indent string
|
||||
FieldSep string
|
||||
|
||||
TimeLayout string
|
||||
DateLayout string
|
||||
IntLayout string
|
||||
FloatLayout string
|
||||
BoolLayout string
|
||||
}
|
||||
|
||||
LayoutFnc func (layouts *Layout)
|
||||
)
|
||||
|
||||
|
||||
|
||||
func newLayouts () *Layout {
|
||||
return &Layout{
|
||||
Indent : " ",
|
||||
FieldSep : " : ",
|
||||
|
||||
TimeLayout : time.RFC822Z,
|
||||
DateLayout : time.RFC822Z,
|
||||
IntLayout : "%d",
|
||||
FloatLayout : "%-10s: %.2f",
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,80 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name show.go
|
||||
// Created by DEV
|
||||
// Modified 07/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package ftext
|
||||
|
||||
|
||||
const (
|
||||
|
||||
AddWrapped Option = 1 << iota
|
||||
AddType
|
||||
AddCode
|
||||
AddFields
|
||||
AddCause
|
||||
AddTrace
|
||||
ShowAnsi
|
||||
UseIndent
|
||||
NotShowEmpty
|
||||
|
||||
optionsDefault = AddWrapped | AddCode | AddType | ShowAnsi | UseIndent | AddFields | AddCause | AddTrace | NotShowEmpty
|
||||
)
|
||||
|
||||
|
||||
type (
|
||||
|
||||
|
||||
Option uint16
|
||||
)
|
||||
|
||||
|
||||
|
||||
func (o Option) SetDefaults () Option {
|
||||
return optionsDefault
|
||||
}
|
||||
|
||||
func (o Option) AddWrapped() bool {
|
||||
return o&AddWrapped !=0 }
|
||||
|
||||
func (o Option) AddType() bool {
|
||||
return o&AddType !=0 }
|
||||
|
||||
func (o Option) AddCode() bool {
|
||||
return o&AddCode != 0 }
|
||||
|
||||
func (o Option) ShowAnsi () bool {
|
||||
return o&ShowAnsi !=0 }
|
||||
|
||||
func (o Option) UseIndent() bool {
|
||||
return o&UseIndent !=0 }
|
||||
|
||||
func (o Option) AddFields() bool {
|
||||
return o&AddFields !=0 }
|
||||
|
||||
func (o Option) AddCause() bool {
|
||||
return o&AddCause !=0 }
|
||||
|
||||
func (o Option) AddTrace() bool {
|
||||
return o&AddTrace !=0 }
|
||||
|
||||
func (o Option) NotShowEmpty() bool {
|
||||
return o&NotShowEmpty !=0 }
|
||||
@ -0,0 +1,58 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name section.go
|
||||
// Created by DEV
|
||||
// Modified 16/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package ftext
|
||||
|
||||
import "ansi"
|
||||
|
||||
type (
|
||||
|
||||
section struct {
|
||||
ansiC ansi.Code
|
||||
beginFn func(textBuilder *TextBuilder)
|
||||
endFn func(textBuilder *TextBuilder)
|
||||
}
|
||||
|
||||
|
||||
)
|
||||
|
||||
|
||||
func (s *section) Set(ansiC ansi.Code, beginFn, endFn TextBuilderFnc) {
|
||||
s.ansiC = ansiC
|
||||
s.beginFn,s.endFn = beginFn,endFn }
|
||||
|
||||
|
||||
func (s *section) begin(txtBuilder *TextBuilder) {
|
||||
txtBuilder.setAnsi(s.ansiC)
|
||||
if s.beginFn != nil {
|
||||
s.beginFn(txtBuilder)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *section) end(txtBuilder *TextBuilder) {
|
||||
txtBuilder.setAnsi(s.ansiC)
|
||||
if s.endFn != nil {
|
||||
s.endFn(txtBuilder)
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sections.go
|
||||
// Created by DEV
|
||||
// Modified 16/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package ftext
|
||||
|
||||
|
||||
type (
|
||||
|
||||
Sections struct {
|
||||
Main section
|
||||
Head section
|
||||
Fields section
|
||||
Causes section
|
||||
Cause section
|
||||
Trace section
|
||||
}
|
||||
|
||||
|
||||
SectionsFnc func(secs *Sections)
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,74 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name text_builder.go
|
||||
// Created by DEV
|
||||
// Modified 22/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package ftext
|
||||
|
||||
import (
|
||||
"ansi"
|
||||
"bytes"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
TextBuilder struct {
|
||||
f *TextFormatter
|
||||
b bytes.Buffer
|
||||
|
||||
ansiC ansi.Code
|
||||
invalid error
|
||||
}
|
||||
|
||||
|
||||
TextBuilderFnc func (b *TextBuilder)
|
||||
)
|
||||
|
||||
func newTextBuilder(formatter *TextFormatter) *TextBuilder {
|
||||
return &TextBuilder{
|
||||
f : formatter,
|
||||
ansiC: formatter.layout.AnsiC}}
|
||||
|
||||
|
||||
|
||||
|
||||
func (s *TextBuilder) format (err error) {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func (s *TextBuilder) setAnsi(ansiC ansi.Code) {
|
||||
if ansiC != 0 {
|
||||
s.ansiC = ansiC
|
||||
} else {
|
||||
s.ansiC = s.f.layout.AnsiC
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (s *TextBuilder) reset () {
|
||||
s.b.Reset()
|
||||
s.f = nil
|
||||
s.invalid = nil
|
||||
}
|
||||
@ -0,0 +1,128 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name text_formatter.go
|
||||
// Created by DEV
|
||||
// Modified 22/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package ftext
|
||||
|
||||
import (
|
||||
"errs/stack"
|
||||
"tbase/astrings"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
|
||||
TextFormatter struct {
|
||||
Option
|
||||
|
||||
layout Layout
|
||||
sections Sections
|
||||
|
||||
nameTrans astrings.Transformers
|
||||
valueTrans astrings.Transformers
|
||||
|
||||
onFormatError ErrorFallbackFnc
|
||||
onTraceError ErrorFallbackFnc
|
||||
onCauseError ErrorFallbackFnc
|
||||
|
||||
frameBuilder func (builder *TextBuilder, frame stack.Frame, num int)
|
||||
}
|
||||
|
||||
TextFormatterFnc func (formatter *TextFormatter)
|
||||
)
|
||||
|
||||
|
||||
func NewTextFormatter(options ...TextFormatterFnc) *TextFormatter {
|
||||
fm := &TextFormatter{
|
||||
Option : optionsDefault,
|
||||
layout : *newLayouts(),
|
||||
frameBuilder : defaultFrameBuilder,
|
||||
onFormatError : defaultFallback,
|
||||
onTraceError : defaultFallback,
|
||||
onCauseError : defaultFallback,
|
||||
}
|
||||
for _,o := range options {
|
||||
o(fm)
|
||||
}
|
||||
return fm
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func (f *TextFormatter) FormatError (err error) []byte {
|
||||
b := newTextBuilder(f)
|
||||
defer func(tb *TextBuilder){
|
||||
tb.reset()
|
||||
}(b)
|
||||
|
||||
b.format(err)
|
||||
return b.b.Bytes()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func WithErrorFallbacks (format, cause, trace ErrorFallbackFnc) TextFormatterFnc {
|
||||
return func(f *TextFormatter) {
|
||||
if format == nil {
|
||||
f.onFormatError = format
|
||||
}
|
||||
if cause == nil {
|
||||
f.onCauseError = cause
|
||||
}
|
||||
if trace == nil {
|
||||
f.onTraceError = trace
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func WithOptions (set, unset Option) TextFormatterFnc {
|
||||
return func(f *TextFormatter) {
|
||||
f.Option |= set
|
||||
f.Option &^= unset } }
|
||||
|
||||
|
||||
func WithNameTransformers(transformer ...astrings.Transformer) TextFormatterFnc {
|
||||
return func(f *TextFormatter) {
|
||||
f.nameTrans = append(f.nameTrans, transformer ...) } }
|
||||
|
||||
|
||||
func WithValueTransformers(transformer ...astrings.Transformer) TextFormatterFnc {
|
||||
return func(f *TextFormatter) {
|
||||
f.valueTrans = append(f.nameTrans, transformer ...) } }
|
||||
|
||||
|
||||
func WithSectionsFormat(config SectionsFnc) TextFormatterFnc {
|
||||
return func(f *TextFormatter) {
|
||||
config(&f.sections) } }
|
||||
|
||||
|
||||
func WithLayouts (config LayoutFnc) TextFormatterFnc {
|
||||
return func(f *TextFormatter) {
|
||||
config(&f.layout) } }
|
||||
|
||||
|
||||
func WithFrameBuilder (builderFn func (builder *TextBuilder, frame stack.Frame, num int)) TextFormatterFnc {
|
||||
return func(f *TextFormatter) {
|
||||
f.frameBuilder = builderFn } }
|
||||
@ -1,41 +0,0 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project atila
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name json_char_atts.go
|
||||
// Created by DEV
|
||||
// Modified 18/01/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package pjson
|
||||
|
||||
const (
|
||||
jsonCharAttUnsafe jsonCharAtt = 1 << iota
|
||||
jsonCharAttHtmlUnsafe
|
||||
|
||||
jsonCharAttAllUnsafe = jsonCharAttUnsafe | jsonCharAttHtmlUnsafe
|
||||
)
|
||||
|
||||
type jsonCharAtt uint8
|
||||
|
||||
func (a jsonCharAtt) isUnsafe() bool {
|
||||
return a&jsonCharAttUnsafe != 0
|
||||
}
|
||||
|
||||
func (a jsonCharAtt) isHtmlUnsafe() bool {
|
||||
return a&jsonCharAttHtmlUnsafe != 0
|
||||
}
|
||||
Loading…
Reference in new issue