mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-07 04:09:15 +02:00
feat:#51 added TR fix for room mapping
This commit is contained in:
@@ -5,20 +5,36 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func MapRoom(room string) string {
|
||||
func MapRoom(room string, output bool) string {
|
||||
// remove dots from room string
|
||||
room = strings.ReplaceAll(room, ".", "")
|
||||
|
||||
if output {
|
||||
//replace second point in TR_A1.23.1 -> TR_A1.23-1 with a minus
|
||||
re := regexp.MustCompile(`\b[TR_]+[A-ZÄÖÜ]?[0-9]{1,4}[.][0-9]{1,4}[.]\b`)
|
||||
room = re.ReplaceAllStringFunc(room, func(match string) string {
|
||||
return match[:len(match)-1] + "-" + match[len(match)-1:]
|
||||
})
|
||||
// If the output flag is set, remove all dots from the room string
|
||||
room = strings.ReplaceAll(room, ".", "")
|
||||
} else {
|
||||
// If the output flag is false add a dot for all rooms with regexp TR_A123 -> TR_A1.23
|
||||
re := regexp.MustCompile(`\bTR_+[A-ZÄÖÜ]?[0-9]{1,4}[a-zäöü]?\b`)
|
||||
room = re.ReplaceAllStringFunc(room, func(match string) string {
|
||||
return match[:len(match)-2] + "." + match[len(match)-2:]
|
||||
})
|
||||
room = strings.ReplaceAll(room, "-", ".")
|
||||
}
|
||||
|
||||
// Regular expression pattern to match room identifiers
|
||||
// The pattern looks for strings that start with two uppercase letters, optionally followed by an underscore,
|
||||
// followed by 1 to 3 digits, and ending with "-[A-Z]"
|
||||
re := regexp.MustCompile(`\b[A-ZÄÖÜ]{2}([_]+[A-ZÄÖÜ])?[0-9]{1,4}[a-zäöü]?-[A-ZÄÖÜ]\b`)
|
||||
re := regexp.MustCompile(`\b[A-ZÄÖÜ]{2}([_]+[A-ZÄÖÜ])?[0-9]{1,4}[a-zäöü]?[-]?[0-9]?-[A-ZÄÖÜ]\b`)
|
||||
|
||||
// Use the ReplaceAllStringFunc to process each match
|
||||
result := re.ReplaceAllStringFunc(room, func(match string) string {
|
||||
room = re.ReplaceAllStringFunc(room, func(match string) string {
|
||||
// Remove the last two characters (i.e., "-<letter>")
|
||||
return match[:len(match)-2]
|
||||
})
|
||||
|
||||
return result
|
||||
return room
|
||||
}
|
||||
|
Reference in New Issue
Block a user