math-optim/algo/util.go

46 lines
840 B
Go
Raw Normal View History

// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package algo
2022-06-28 23:40:35 +02:00
import (
"errors"
"log"
"os"
"strings"
)
func sanitiseFName(s string) string {
return strings.ReplaceAll(s, " ", "_")
}
2022-06-28 23:40:35 +02:00
// createFolder creates a folder at the specified path, if it doesn't already
// exist.
func createFolder(path string) error {
var err error
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {
err = os.Mkdir(path, os.ModePerm)
if err != nil {
log.Println(err)
}
}
return err
}
2022-06-29 16:54:55 +02:00
// createPath creates all folders in the provided path, if they don't already
// exist.
func createPath(path string) error {
var err error
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {
err = os.MkdirAll(path, os.ModePerm)
if err != nil {
log.Println(err)
}
}
return err
}