| 1 |
package cli |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"fmt" |
| 6 |
) |
| 7 |
|
| 8 |
func parseDatabaseAndRetentionPolicy(stmt []byte) (string, string, error) { |
| 9 |
var db, rp []byte |
| 10 |
var quoted bool |
| 11 |
var seperatorCount int |
| 12 |
|
| 13 |
stmt = bytes.TrimSpace(stmt) |
| 14 |
|
| 15 |
for _, b := range stmt { |
| 16 |
if b == '"' { |
| 17 |
quoted = !quoted |
| 18 |
continue |
| 19 |
} |
| 20 |
if b == '.' && !quoted { |
| 21 |
seperatorCount++ |
| 22 |
if seperatorCount > 1 { |
| 23 |
return "", "", fmt.Errorf("unable to parse database and retention policy from %s", string(stmt)) |
| 24 |
} |
| 25 |
continue |
| 26 |
} |
| 27 |
if seperatorCount == 1 { |
| 28 |
rp = append(rp, b) |
| 29 |
continue |
| 30 |
} |
| 31 |
db = append(db, b) |
| 32 |
} |
| 33 |
return string(db), string(rp), nil |
| 34 |
} |