Movatterモバイル変換


[0]ホーム

URL:


nfp

packagemodule
v0.0.0-...-82a408bLatest Latest
Warning

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

Go to latest
Published: Jan 11, 2025 License:BSD-3-ClauseImports:1Imported by:50

Details

Repository

github.com/xuri/nfp

README

NFP (Number Format Parser)

Build StatusCode CoverageGo Report Cardgo.devLicenses

Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression.

Installation

go get github.com/xuri/nfp

Example

package mainimport "github.com/xuri/nfp"func main() {    ps := nfp.NumberFormatParser()    tokens := ps.Parse("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)")    println(p.PrettyPrint())}

Get AST

<Positive>      <RepeatsChar>    # <HashPlaceHolder>    <ThousandsSeparator>    ## <HashPlaceHolder>    0 <ZeroPlaceHolder>    . <DecimalPoint>    00 <ZeroPlaceHolder><Negative>      <RepeatsChar>    ( <Literal>    # <HashPlaceHolder>    , <ThousandsSeparator>    ## <HashPlaceHolder>    0 <ZeroPlaceHolder>    . <DecimalPoint>    00 <ZeroPlaceHolder>    ) <Literal><Zero>      <RepeatsChar>    - <Literal>    ?? <DigitalPlaceHolder><Text>    @ <TextPlaceHolder>

Contributing

Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.

Licenses

This program is under the terms of the BSD 3-Clause License. Seehttps://opensource.org/licenses/BSD-3-Clause.

Documentation

Index

Constants

View Source
const (// Character constantsAsterisk       = "*"At             = "@"BackSlash      = "\\"BlockDelimiter = ";"BracketClose   = "]"BracketOpen    = "["Colon          = ":"Comma          = ","Dash           = "-"Dollar         = "$"Dot            = "."Hash           = "#"ParenClose     = ")"ParenOpen      = "("Percent        = "%"Plus           = "+"Question       = "?"QuoteDouble    = "\""QuoteSingle    = "'"Slash          = "/"Underscore     = "_"Whitespace     = " "Zero           = "0"// DatesTimesCodeChars defined dates and times control codes in upper caseDatesTimesCodeChars = "AEYMDHSG"// NumCodeChars defined numeric code characterNumCodeChars = "0123456789"// Token section typesTokenSectionNegative = "Negative"TokenSectionPositive = "Positive"TokenSectionText     = "Text"TokenSectionZero     = "Zero"// Token subtypesTokenSubTypeCurrencyString = "CurrencyString"TokenSubTypeLanguageInfo   = "LanguageInfo"TokenTypeColor             = "Color"// Token typesTokenTypeAlignment          = "Alignment"TokenTypeCondition          = "Condition"TokenTypeCurrencyLanguage   = "CurrencyLanguage"TokenTypeDateTimes          = "DateTimes"TokenTypeDecimalPoint       = "DecimalPoint"TokenTypeDenominator        = "Denominator"TokenTypeDigitalPlaceHolder = "DigitalPlaceHolder"TokenTypeElapsedDateTimes   = "ElapsedDateTimes"TokenTypeExponential        = "Exponential"TokenTypeFraction           = "Fraction"TokenTypeGeneral            = "General"TokenTypeHashPlaceHolder    = "HashPlaceHolder"TokenTypeLiteral            = "Literal"TokenTypeOperand            = "Operand"TokenTypeOperator           = "Operator"TokenTypePercent            = "Percent"TokenTypeRepeatsChar        = "RepeatsChar"TokenTypeSwitchArgument     = "SwitchArgument"TokenTypeTextPlaceHolder    = "TextPlaceHolder"TokenTypeThousandsSeparator = "ThousandsSeparator"TokenTypeUnknown            = "Unknown"TokenTypeZeroPlaceHolder    = "ZeroPlaceHolder")

Asterisk, At and other's constants are token definitions.

Variables

View Source
var AmPm = []string{"AM/PM", "A/P", "上午/下午"}

AmPm defined the AM and PM with international considerations.

View Source
var ColorNames = []string{"black","blue","cyan","green","magenta","red","white","yellow",}

ColorNames defined colors name used in for a section of the format, use thename of one of the following eight colors in square brackets in thesection. The color code shall be the first item in the section.

View Source
var ConditionOperators = []string{"<", "<=", ">", ">=", "<>", "="}

ConditionOperators defined the condition operators.

View Source
var GeneralFormattingSwitchArguments = []string{"AIUEO","ALPHABETIC","alphabetic","Arabic","ARABICABJAD","ARABICALPHA","ArabicDash","BAHTTEXT","CardText","CHINESENUM1","CHINESENUM2","CHINESENUM3","CHOSUNG","CIRCLENUM","DBCHAR","DBNUM1","DBNUM2","DBNUM3","DBNUM4","DollarText","GANADA","GB1","GB2","GB3","GB4","HEBREW1","HEBREW2","Hex","HINDIARABIC","HINDICARDTEXT","HINDILETTER1","HINDILETTER2","IROHA","KANJINUM1","KANJINUM2","KANJINUM3","Ordinal","OrdText","Roman","roman","SBCHAR","THAIARABIC","THAICARDTEXT","THAILETTER","VIETCARDTEXT","ZODIAC1","ZODIAC2","ZODIAC3",}

GeneralFormattingSwitchArguments defined switch-arguments apply to fieldswhose field result is a numeric value. If the result type of the field isnot numeric, then these switches have no effect.

Functions

This section is empty.

Types

typeParser

type Parser struct {InBracketboolInStringboolInPlaceholderboolNumFmtstring// Runes is a copy of the number format string as a rune slice. It's stored here to avoid// allocating a new slice every time we need to access it.Runes  []runeOffsetintTokensTokensTokenToken}

Parser inheritable container.

funcNumberFormatParser

func NumberFormatParser()Parser

NumberFormatParser provides function to parse an Excel number format into astream of tokens.

func (*Parser)EOF

func (ps *Parser) EOF()bool

EOF provides function to check whether end of tokens stack.

func (*Parser)Parse

func (ps *Parser) Parse(numFmtstring) []Section

Parse provides function to parse number format as a token stream (list).

func (*Parser)PrettyPrint

func (ps *Parser) PrettyPrint()string

PrettyPrint provides function to pretty the parsed result with the indentedformat.

typePart

type Part struct {TokenTokenValuestring}

Part directly maps the sub part of the token.

typeSection

type Section struct {TypestringItems []Token}

Section directly maps sections of the number format. Up to four sections offormat codes can be specified. The format codes, separated by semicolons,define the formats for positive numbers, negative numbers, zero values, andtext, in that order. If only two sections are specified, the first is usedfor positive numbers and zeros, and the second is used for negativenumbers. If only one section is specified, it is used for all numbers. Toskip a section, the ending semicolon for that section shall be written.

typeToken

type Token struct {TValuestringTTypestringParts  []Part}

Token encapsulate a number format token.

typeTokens

type Tokens struct {IndexintSectionIndexintSections     []Section}

Tokens directly maps the ordered list of tokens.Attributes:

Index        - Current position in the number format expressionSectionIndex - Current position in sectionSections     - Ordered section of token sequences

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp