-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To help with ambiguous cases, for example when it is not clear if `Aus (Bus) cus` has a genus Author `Bus` (bot.) or it is a `Bus` is a subgenus of `Aus` (zool.). It also deprecates cultivar flag, which becomes another option for the code flag. The cultivar flag will be kept for backward compatibility.
- Loading branch information
Showing
2 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package nomcode | ||
|
||
import ( | ||
"log/slog" | ||
"strings" | ||
) | ||
|
||
// Code represents a nomenclatural code. | ||
type Code int | ||
|
||
// Constants for different nomenclatural codes. | ||
const ( | ||
Unknown Code = iota // Unknown code | ||
Zoological // Zoological code | ||
Botanical // Botanical code | ||
Cultivar // Cultivar code | ||
) | ||
|
||
// New creates a new Code from a string representation. | ||
// It accepts short codes ('b', 'z', 'c') and full names | ||
// ('botanical', 'zoological', 'cultivar') as well as | ||
// official abbreviations ('icn', 'iczn', 'icncp'). | ||
// The input string is case-insensitive. | ||
func New(s string) Code { | ||
sOrig := s | ||
s = strings.ToLower(s) | ||
switch s { | ||
case "b", "bot", "botanical", "icn": | ||
return Botanical | ||
case "z", "zoo", "zoological", "iczn": | ||
return Zoological | ||
case "c", "cult", "cultivar", "icncp": | ||
return Cultivar | ||
default: | ||
slog.Warn("Cannot determine nomenclatural code", "input", sOrig) | ||
return Unknown | ||
} | ||
} | ||
|
||
// String returns the official abbreviation of the nomenclatural code. | ||
func (c Code) String() string { | ||
switch c { | ||
case Zoological: | ||
return "ICZN" | ||
case Botanical: | ||
return "ICN" | ||
case Cultivar: | ||
return "ICNCP" | ||
default: | ||
return "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters