Commit 1b766d80 authored by Cristian Maglie's avatar Cristian Maglie

Moved SanitizeName into his own module

parent d39c1e04
......@@ -37,6 +37,7 @@ import (
"github.com/bcmi-labs/arduino-cli/arduino/libraries"
"github.com/bcmi-labs/arduino-cli/arduino/libraries/librariesindex"
"github.com/bcmi-labs/arduino-cli/arduino/utils"
"github.com/bcmi-labs/arduino-cli/configs"
)
......@@ -69,7 +70,7 @@ func Install(library *librariesindex.Release) (string, error) {
return "", fmt.Errorf("getting libraries directory: %s", err)
}
libPath := filepath.Join(libsFolder, sanitizeName(library.Library.Name))
libPath := filepath.Join(libsFolder, utils.SanitizeName(library.Library.Name))
return libPath, library.Resource.Install(libsFolder, libPath)
}
......@@ -79,7 +80,7 @@ func removeRelease(libName string, r *libraries.Library) error {
return err
}
libName = sanitizeName(libName)
libName = utils.SanitizeName(libName)
path := filepath.Join(libFolder, libName)
return os.RemoveAll(path)
}
......@@ -27,9 +27,11 @@
* Copyright 2018 ARDUINO AG (http://www.arduino.cc/)
*/
package librariesmanager
package utils
func sanitizeName(origName string) string {
// SanitizeName replaces with underscores all chars that are not included
// in the ranges: 0-9, A-Z, a-z, "-" and "."
func SanitizeName(origName string) string {
sanitized := ""
for i, c := range origName {
if (c >= '0' && c <= '9') ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment