| | |
| | | |
| | | // RestoreFloor restores the three-character string back to the original floor string |
| | | func RestoreFloor(encoded string) (string, string, error) { |
| | | if len(encoded) != 4 { |
| | | var direction, sign uint8 |
| | | var floorNumber, floorStr, directionStr string |
| | | |
| | | // 3位是旧的格式, 为了兼容, 暂时保留 |
| | | if len(encoded) == 3 { |
| | | sign = encoded[0] |
| | | floorNumber = encoded[1:] |
| | | } else if len(encoded) == 4 { |
| | | direction = encoded[0] |
| | | sign = encoded[1] |
| | | floorNumber = encoded[2:] |
| | | } else { |
| | | return "", "", fmt.Errorf("encoded string must be 3 characters long") |
| | | } |
| | | |
| | | direction := encoded[0] |
| | | sign := encoded[1] |
| | | number := encoded[2:] |
| | | |
| | | // Convert the number back to integer to remove any leading zeros |
| | | parsedNumber, err := strconv.Atoi(number) |
| | | parsedNumber, err := strconv.Atoi(floorNumber) |
| | | if err != nil { |
| | | return "", "", err |
| | | } |
| | | |
| | | var floorStr, directionStr string |
| | | if sign == '1' { |
| | | floorStr = fmt.Sprintf("-%dF", parsedNumber) |
| | | } else if sign == '0' { |