convertUnicode converts the ValueAfterParsed and ValueBeforeParsed fields of a struct to Chinese text. It takes a pointer to a struct and returns an error if the conversion fails.
(p interface{})
| 280 | // convertUnicode converts the ValueAfterParsed and ValueBeforeParsed fields of a struct to Chinese text. |
| 281 | // It takes a pointer to a struct and returns an error if the conversion fails. |
| 282 | func convertUnicode(p interface{}) errors.Error { |
| 283 | var err errors.Error |
| 284 | pType := reflect.TypeOf(p) |
| 285 | if pType.Kind() != reflect.Ptr { |
| 286 | panic("expected a pointer to a struct") |
| 287 | } |
| 288 | pValue := reflect.ValueOf(p).Elem() |
| 289 | if pValue.Kind() != reflect.Struct { |
| 290 | panic("expected a pointer to a struct") |
| 291 | } |
| 292 | after, err := errors.Convert01(unicodeToZh(pValue.FieldByName("ValueAfterParsed").String())) |
| 293 | if err != nil { |
| 294 | return err |
| 295 | } |
| 296 | before, err := errors.Convert01(unicodeToZh(pValue.FieldByName("ValueBeforeParsed").String())) |
| 297 | if err != nil { |
| 298 | return err |
| 299 | } |
| 300 | if after == "--" { |
| 301 | after = "" |
| 302 | } |
| 303 | if before == "--" { |
| 304 | before = "" |
| 305 | } |
| 306 | // Set ValueAfterParsed and ValueBeforeParsed fields |
| 307 | valueAfterField := pValue.FieldByName("ValueAfterParsed") |
| 308 | valueAfterField.SetString(after) |
| 309 | valueBeforeField := pValue.FieldByName("ValueBeforeParsed") |
| 310 | valueBeforeField.SetString(before) |
| 311 | return nil |
| 312 | } |
| 313 | |
| 314 | // replaceSemicolonWithComma replaces all semicolons with commas in the given string |
| 315 | // and trims any trailing commas. It returns the modified string. |