Skip to content

Commit

Permalink
support escaped string literal basic string and use GitHub Action ins…
Browse files Browse the repository at this point in the history
…tead of TravisCI

- Note that: travis-ci.org will shutdown on June 15th, 2021, and I don't have enough permission to migrate this project to travis-ci.com currently
  • Loading branch information
xuri committed Jun 11, 2021
1 parent 3816253 commit 83e12cc
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 29 deletions.
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align="center"><img width="650" src="./excelize.svg" alt="Excelize logo"></p>

<p align="center">
<a href="https://travis-ci.org/360EntSecGroup-Skylar/excelize"><img src="https://travis-ci.org/360EntSecGroup-Skylar/excelize.svg?branch=master" alt="Build Status"></a>
<a href="https://github.com/360EntSecGroup-Skylar/excelize/actions/workflows/go.yml"><img src="https://github.com/360EntSecGroup-Skylar/excelize/actions/workflows/go.yml/badge.svg" alt="Build Status"></a>
<a href="https://codecov.io/gh/360EntSecGroup-Skylar/excelize"><img src="https://codecov.io/gh/360EntSecGroup-Skylar/excelize/branch/master/graph/badge.svg" alt="Code Coverage"></a>
<a href="https://goreportcard.com/report/github.com/360EntSecGroup-Skylar/excelize"><img src="https://goreportcard.com/badge/github.com/360EntSecGroup-Skylar/excelize" alt="Go Report Card"></a>
<a href="https://pkg.go.dev/github.com/360EntSecGroup-Skylar/excelize/v2?tab=doc"><img src="https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white" alt="go.dev"></a>
Expand Down Expand Up @@ -86,6 +86,10 @@ func main() {
fmt.Println(cell)
// Get all the rows in the Sheet1.
rows, err := f.GetRows("Sheet1")
if err != nil {
fmt.Println(err)
return
}
for _, row := range rows {
for _, colCell := range row {
fmt.Print(colCell, "\t")
Expand Down
6 changes: 5 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align="center"><img width="650" src="./excelize.svg" alt="Excelize logo"></p>

<p align="center">
<a href="https://travis-ci.org/360EntSecGroup-Skylar/excelize"><img src="https://travis-ci.org/360EntSecGroup-Skylar/excelize.svg?branch=master" alt="Build Status"></a>
<a href="https://github.com/360EntSecGroup-Skylar/excelize/actions/workflows/go.yml"><img src="https://github.com/360EntSecGroup-Skylar/excelize/actions/workflows/go.yml/badge.svg" alt="Build Status"></a>
<a href="https://codecov.io/gh/360EntSecGroup-Skylar/excelize"><img src="https://codecov.io/gh/360EntSecGroup-Skylar/excelize/branch/master/graph/badge.svg" alt="Code Coverage"></a>
<a href="https://goreportcard.com/report/github.com/360EntSecGroup-Skylar/excelize"><img src="https://goreportcard.com/badge/github.com/360EntSecGroup-Skylar/excelize" alt="Go Report Card"></a>
<a href="https://pkg.go.dev/github.com/360EntSecGroup-Skylar/excelize/v2?tab=doc"><img src="https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white" alt="go.dev"></a>
Expand Down Expand Up @@ -86,6 +86,10 @@ func main() {
fmt.Println(cell)
// 获取 Sheet1 上所有单元格
rows, err := f.GetRows("Sheet1")
if err != nil {
fmt.Println(err)
return
}
for _, row := range rows {
for _, colCell := range row {
fmt.Print(colCell, "\t")
Expand Down
4 changes: 4 additions & 0 deletions chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
//
// Set the primary horizontal and vertical axis options by x_axis and y_axis. The properties of x_axis that can be set are:
//
// none
// major_grid_lines
// minor_grid_lines
// tick_label_skip
Expand All @@ -748,13 +749,16 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
//
// The properties of y_axis that can be set are:
//
// none
// major_grid_lines
// minor_grid_lines
// major_unit
// reverse_order
// maximum
// minimum
//
// none: Disable axes.
//
// major_grid_lines: Specifies major gridlines.
//
// minor_grid_lines: Specifies minor gridlines.
Expand Down
46 changes: 46 additions & 0 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/xml"
"fmt"
"io"
"regexp"
"strconv"
"strings"
)
Expand Down Expand Up @@ -454,6 +455,51 @@ func isNumeric(s string) (bool, int) {
return true, p
}

// bstrUnmarshal parses the binary basic string, this will trim escaped string
// literal which not permitted in an XML 1.0 document. The basic string
// variant type can store any valid Unicode character. Unicode characters
// that cannot be directly represented in XML as defined by the XML 1.0
// specification, shall be escaped using the Unicode numerical character
// representation escape character format _xHHHH_, where H represents a
// hexadecimal character in the character's value. For example: The Unicode
// character 8 is not permitted in an XML 1.0 document, so it shall be
// escaped as _x0008_. To store the literal form of an escape sequence, the
// initial underscore shall itself be escaped (i.e. stored as _x005F_). For
// example: The string literal _x0008_ would be stored as _x005F_x0008_.
func bstrUnmarshal(s string) (result string) {
m := regexp.MustCompile(`_x[a-zA-Z0-9]{4}_`)
escapeExp := regexp.MustCompile(`x[a-zA-Z0-9]{4}_`)
matches := m.FindAllStringSubmatchIndex(s, -1)
var cursor int
for _, match := range matches {
result += s[cursor:match[0]]
if s[match[0]:match[1]] == "_x005F_" {
if len(s) > match[1]+6 && !escapeExp.MatchString(s[match[1]:match[1]+6]) {
result += s[match[0]:match[1]]
cursor = match[1]
continue
}
if len(s) > match[1]+5 && s[match[1]:match[1]+5] == "x005F" {
result += "_"
cursor = match[1]
continue
}
if escapeExp.MatchString(s[match[0]:match[1]]) {
result += "_"
cursor = match[1]
continue
}
}
if escapeExp.MatchString(s[match[0]:match[1]]) {
cursor = match[1]
}
}
if cursor < len(s) {
result += s[cursor:]
}
return result
}

// Stack defined an abstract data type that serves as a collection of elements.
type Stack struct {
list *list.List
Expand Down
19 changes: 19 additions & 0 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,22 @@ func TestGenXMLNamespace(t *testing.T) {
{Name: xml.Name{Space: NameSpaceXML, Local: "space"}, Value: "preserve"},
}), `xml:space="preserve">`)
}

func TestBstrUnmarshal(t *testing.T) {
bstrs := map[string]string{
"*": "*",
"*_x0008_": "*",
"_x0008_*": "*",
"*_x0008_*": "**",
"*_x005F__x0008_*": "*_x005F_*",
"*_x005F_x0001_*": "*_x0001_*",
"*_x005F_x005F_x005F_x0006_*": "*_x005F_x0006_*",
"_x005F__x0008_******": "_x005F_******",
"******_x005F__x0008_": "******_x005F_",
"******_x005F__x0008_******": "******_x005F_******",
"*_x005F_x005F__x0008_*": "*_x005F_*",
}
for bstr, expected := range bstrs {
assert.Equal(t, expected, bstrUnmarshal(bstr))
}
}
4 changes: 2 additions & 2 deletions xmlSharedStrings.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func (x xlsxSI) String() string {
rows.WriteString(s.T.Val)
}
}
return rows.String()
return bstrUnmarshal(rows.String())
}
if x.T != nil {
return x.T.Val
return bstrUnmarshal(x.T.Val)
}
return ""
}
Expand Down

0 comments on commit 83e12cc

Please sign in to comment.