setSharedString provides a function to add string to the share string table.
(val string)
| 485 | |
| 486 | // setSharedString provides a function to add string to the share string table. |
| 487 | func (f *File) setSharedString(val string) (int, error) { |
| 488 | if err := f.sharedStringsLoader(); err != nil { |
| 489 | return 0, err |
| 490 | } |
| 491 | sst, err := f.sharedStringsReader() |
| 492 | if err != nil { |
| 493 | return 0, err |
| 494 | } |
| 495 | f.mu.Lock() |
| 496 | defer f.mu.Unlock() |
| 497 | if i, ok := f.sharedStringsMap[val]; ok { |
| 498 | return i, nil |
| 499 | } |
| 500 | sst.mu.Lock() |
| 501 | defer sst.mu.Unlock() |
| 502 | t := xlsxT{Val: val} |
| 503 | val, t.Space = trimCellValue(val, false) |
| 504 | sst.SI = append(sst.SI, xlsxSI{T: &t}) |
| 505 | sst.Count = len(sst.SI) |
| 506 | sst.UniqueCount = sst.Count |
| 507 | f.sharedStringsMap[val] = sst.UniqueCount - 1 |
| 508 | return sst.UniqueCount - 1, nil |
| 509 | } |
| 510 | |
| 511 | // trimCellValue provides a function to set string type to cell. |
| 512 | func trimCellValue(value string, escape bool) (v string, ns xml.Attr) { |
no test coverage detected