phonekeypad

package
v1.99.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package phonekeypad provides functions to convert number strings to sequences of numbers corresponding to a standard phone keypad:

+-----+-----+-----+
|  1  |  2  |  3  |
|     | ABC | DEF |
+-----+-----+-----+
|  4  |  5  |  6  |
| GHI | JKL | MNO |
+-----+-----+-----+
|  7  |  8  |  9  |
| PQRS| TUV | WXYZ|
+-----+-----+-----+
|     |  0  |     |
|     |     |     |
+-----+-----+-----+

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeypadDigit

func KeypadDigit(r rune) (int, bool)

KeypadDigit converts the input rune to a number corresponding to a standard phone keypad. If the input rune is not a number or a letter between A-Z or a-z, it returns -1 and false. Otherwise, it returns the corresponding number and true.

The letter mapping is as follows:

  • A, B, C -> 2
  • D, E, F -> 3
  • G, H, I -> 4
  • J, K, L -> 5
  • M, N, O -> 6
  • P, Q, R, S -> 7
  • T, U, V -> 8
  • W ,X, Y, Z -> 9
Example
package main

import (
	"fmt"

	"github.com/Vonage/gosrvlib/pkg/phonekeypad"
)

func main() {
	phoneNumber := "999-EXAMPLE-1"
	numSeq := make([]int, 0, len(phoneNumber))

	for _, r := range phoneNumber {
		v, status := phonekeypad.KeypadDigit(r)
		if status {
			numSeq = append(numSeq, v)
		}
	}

	fmt.Println(numSeq)

}
Output:

[9 9 9 3 9 2 6 7 5 3 1]

func KeypadNumber

func KeypadNumber(num string) []int

KeypadNumber converts the input string to a sequence of numbers corresponding to a standard phone keypad. It skips any characters that are not numbers or letters between A-Z or a-z. See: KeypadDigit().

Example
package main

import (
	"fmt"

	"github.com/Vonage/gosrvlib/pkg/phonekeypad"
)

func main() {
	phoneNumber := "999-EXAMPLE-2"

	numSeq := phonekeypad.KeypadNumber(phoneNumber)

	fmt.Println(numSeq)

}
Output:

[9 9 9 3 9 2 6 7 5 3 2]

func KeypadNumberString

func KeypadNumberString(num string) string

KeypadNumberString converts the input string to a sequence of numbers corresponding to a standard phone keypad. It skips any characters that are not numbers or letters between A-Z or a-z. It returns the sequence as a string. See: KeypadDigit().

Example
package main

import (
	"fmt"

	"github.com/Vonage/gosrvlib/pkg/phonekeypad"
)

func main() {
	phoneNumber := "999-EXAMPLE-3"

	numStr := phonekeypad.KeypadNumberString(phoneNumber)

	fmt.Println(numStr)

}
Output:

99939267533

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL