Skip to content

Commit

Permalink
Merge pull request #10 from shakinm/hotfix/fix_sst
Browse files Browse the repository at this point in the history
fix sst.read
  • Loading branch information
shakinm authored Apr 6, 2020
2 parents 88fca6c + 81e9dbb commit 1574c4b
Showing 1 changed file with 73 additions and 12 deletions.
85 changes: 73 additions & 12 deletions xls/record/sst.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ func (s *SST) Read(readType string, grbit byte, prevLen int32) () {
if len(s.RgbSrc) == 0 {
return
}

oft := uint32(0)

for {

var _rgb structure.XLUnicodeRichExtendedString
var rgbSize int

cch := int(helpers.BytesToUint16(s.RgbSrc[0:2]))

Expand All @@ -81,21 +80,83 @@ func (s *SST) Read(readType string, grbit byte, prevLen int32) () {

readType = ""

addBytesLen := (len(s.RgbSrc) - 3) - s.ByteLen
if cch >= (len(s.RgbSrc)-3)/(1+int(grbit&1)) || s.ByteLen > 0 {

addBytesLen := (len(s.RgbSrc) - 3) - s.ByteLen

if cch-s.chLen > addBytesLen/(1+int(grbit&1)) {
s.chLen = s.chLen + addBytesLen/(1+int(grbit&1))
s.ByteLen = s.ByteLen + addBytesLen
return
} else {

s.ByteLen = s.ByteLen + (cch-s.chLen)*(1+int(grbit&1))
s.chLen = cch
rgbSize = s.ByteLen
}

if cch-s.chLen > addBytesLen/(1+int(grbit)) {
s.chLen = s.chLen + addBytesLen/(1+int(grbit))
s.ByteLen = s.ByteLen + addBytesLen
return
} else {
s.ByteLen = s.ByteLen + (cch-s.chLen)*(1+int(grbit))
s.chLen = cch
rgbSize = cch * (1 + int(grbit&1))
}

copy(_rgb.Cch[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])

_rgb.FHighByte = s.RgbSrc[iOft(&oft, 0):iOft(&oft, 1)][0]

if _rgb.FHighByte>>3&1 == 1 { // if fRichSt == 1
copy(_rgb.CRun[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])
}

if _rgb.FHighByte>>2&1 == 1 { //fExtSt == 1
copy(_rgb.CbExtRst[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 4)])
}

//offset rgbSize
_rgb.Rgb = make([]byte, uint32(rgbSize))
copy(_rgb.Rgb[0:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, uint32(rgbSize))])

if _rgb.FHighByte>>3&1 == 1 { // if fRichSt == 1
cRunSize := helpers.BytesToUint16(_rgb.CRun[:])
for i := uint16(0); i <= cRunSize-1; i++ {
var rgRun structure.FormatRun
copy(rgRun.Ich[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])
copy(rgRun.Ifnt.Ifnt[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])
_rgb.RgRun = append(_rgb.RgRun, rgRun)
}
}

realSize := _rgb.Read(s.RgbSrc[iOft(&oft, 0):])
iOft(&oft, realSize)
if _rgb.FHighByte>>2&1 == 1 { //fExtSt == 1
copy(_rgb.ExtRst.Reserved[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])
copy(_rgb.ExtRst.Cb[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])

copy(_rgb.ExtRst.Phs.Ifnt.Ifnt[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])
copy(_rgb.ExtRst.Phs.Info[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])

copy(_rgb.ExtRst.Rphssub.Crun[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])
copy(_rgb.ExtRst.Rphssub.Cch[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])

copy(_rgb.ExtRst.Rphssub.St.CchCharacters[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])

rgchDataSize := helpers.BytesToUint16(_rgb.ExtRst.Rphssub.St.CchCharacters[:]) * 2
for i := uint16(0); i <= rgchDataSize; i++ {
_rgb.ExtRst.Rphssub.St.RgchData = append(_rgb.ExtRst.Rphssub.St.RgchData, s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)]...)
}

//The number of elements in this array is rphssub.crun
phRunsSizeL := helpers.BytesToUint16(_rgb.ExtRst.Rphssub.Crun[:])
if phRunsSizeL > 0 {
for i := uint16(0); i <= phRunsSizeL; i++ {
var phRuns structure.PhRuns
copy(phRuns.IchFirst[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])
copy(phRuns.IchMom[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])
copy(phRuns.CchMom[:], s.RgbSrc[iOft(&oft, 0):iOft(&oft, 2)])

_rgb.ExtRst.Rgphruns = append(_rgb.ExtRst.Rgphruns, phRuns)
}
}
}

if len(s.RgbSrc) >= int(realSize) {
if len(s.RgbSrc) >= int(oft) {
s.Rgb = append(s.Rgb, _rgb)
s.RgbSrc = s.RgbSrc[int(oft):]
s.chLen = 0
Expand Down

0 comments on commit 1574c4b

Please # to comment.