fix for windows and linux newline formats
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/response.txt
|
||||||
|
/llmparse.exe
|
BIN
llmparse.exe
BIN
llmparse.exe
Binary file not shown.
12
main.go
12
main.go
@ -36,30 +36,28 @@ func main() {
|
|||||||
|
|
||||||
text := string(data)
|
text := string(data)
|
||||||
|
|
||||||
// Regular expression to match each file block.
|
// Updated regular expression to handle both LF and CRLF line breaks.
|
||||||
// It matches a line starting with "File:" followed by the file name,
|
re := regexp.MustCompile(`(?s)File:\s*(.+?)\s*\r?\n-+\r?\n(.*?)(\r?\n-+\r?\n|$)`)
|
||||||
// then a divider line with dashes, then captures everything until the next divider.
|
|
||||||
re := regexp.MustCompile(`(?s)File:\s*(.+?)\s*\n-+\n(.*?)(\n-+\n|$)`)
|
|
||||||
matches := re.FindAllStringSubmatch(text, -1)
|
matches := re.FindAllStringSubmatch(text, -1)
|
||||||
if matches == nil {
|
if matches == nil {
|
||||||
log.Println("No file entries found in the input.")
|
log.Println("No file entries found in the input.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the output directory exists
|
// Ensure the output directory exists.
|
||||||
if err := os.MkdirAll(*outDir, os.ModePerm); err != nil {
|
if err := os.MkdirAll(*outDir, os.ModePerm); err != nil {
|
||||||
log.Fatalf("Error creating output directory %s: %v", *outDir, err)
|
log.Fatalf("Error creating output directory %s: %v", *outDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, match := range matches {
|
for _, match := range matches {
|
||||||
// match[1] will be the file name, match[2] the file content.
|
// match[1] is the file name, and match[2] is the file content.
|
||||||
fileName := match[1]
|
fileName := match[1]
|
||||||
fileContent := match[2]
|
fileContent := match[2]
|
||||||
|
|
||||||
// Create the full file path using the output directory.
|
// Create the full file path using the output directory.
|
||||||
fullPath := filepath.Join(*outDir, fileName)
|
fullPath := filepath.Join(*outDir, fileName)
|
||||||
|
|
||||||
// Ensure that the directory for the file exists (in case there's nesting).
|
// Ensure that the directory for the file exists (in case there's nested directories).
|
||||||
dir := filepath.Dir(fullPath)
|
dir := filepath.Dir(fullPath)
|
||||||
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
||||||
log.Printf("Error creating directory %s: %v", dir, err)
|
log.Printf("Error creating directory %s: %v", dir, err)
|
||||||
|
Reference in New Issue
Block a user