util

package
v1.2.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Copyright Consensys Software Inc.

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.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

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.

SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	// FORMAT_NONE indicates an empty format string
	FORMAT_NONE uint = iota
	// FORMAT_DEC indicates to format in decimal
	FORMAT_DEC
	// FORMAT_HEX indicates to format in hexadecimal
	FORMAT_HEX
	// FORMAT_BIN indicates to format in binary
	FORMAT_BIN
	// FORMAT_CHR indicates to format as a single ASCII character.  The
	// argument is required (at type-check time) to be a concrete u8; the
	// rendered output is the single byte interpreted as a character.
	FORMAT_CHR
)

Variables

View Source
var EMPTY_FORMAT = Format{Code: FORMAT_NONE}

EMPTY_FORMAT indicates no formatted argument is required.

Functions

func EscapeFormattedText

func EscapeFormattedText(text string) string

EscapeFormattedText takes a string and escapes any characters which need to be escaped in order to be printed.

func ParseJsonInputFile

func ParseJsonInputFile(bytes []byte) (map[string][]byte, error)

ParseJsonInputFile parses a json input file into an input / output mapping, as suitable for booting a machine with. This can fail with a parsing error.

Types

type Format

type Format struct {
	Code    uint
	Width   uint
	ZeroPad bool
}

Format simply encodes the set of permitted formatting strings in a printf statement, such as "%d", "%x", "%08x", "%8x", etc. Width specifies an optional minimum number of digits to render, and ZeroPad selects between zero-padding ('0' flag) and space-padding (the default). Any base prefix ("0x", "0b") is rendered separately and does not count towards Width.

func BinFormat

func BinFormat() Format

BinFormat constructs a new binary format.

func CharFormat

func CharFormat() Format

CharFormat constructs a new character format. %c does not support width/zero-padding flags; the parser rejects them before this is reached.

func DecimalFormat

func DecimalFormat() Format

DecimalFormat constructs a new decimal format.

func HexFormat

func HexFormat() Format

HexFormat constructs a new hexadecimal format.

func (Format) HasFormat

func (p Format) HasFormat() bool

HasFormat checks whether this actually represents a format, or is empty.

func (Format) Render

func (p Format) Render(value *big.Int) string

Render formats the given (non-negative) integer value according to this format, applying the selected base, then any minimum width and padding. This is the shared rendering used by the machine interpreters when producing debug / printf output, ensuring the reference word machine and the bytecode interpreter agree on the exact text emitted.

func (Format) String

func (p Format) String() string

type Formattable

type Formattable interface {
	// Text returns the given word formated in the given base
	Text(base int) string
	// BigInt returns big integer representation of value.
	BigInt() *big.Int
}

Formattable captures a numeric element which can be formatted in a particular base.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL