summaryrefslogtreecommitdiff
path: root/guix/build/po.scm
diff options
context:
space:
mode:
authorJakub Kądziołka <kuba@kadziolka.net>2020-07-23 21:43:06 +0200
committerJakub Kądziołka <kuba@kadziolka.net>2020-07-23 21:43:06 +0200
commitd726b954baaeff876ce9728e00920fa45f529f9a (patch)
tree4b767b7586a1082dd2691bc33c3e45ace044e6e5 /guix/build/po.scm
parent9a74a7db8626bc139307d115f5cec2648f5273ad (diff)
parente165a2492d73d37c8b95d6970d453b9d88911ee6 (diff)
Merge branch 'master' into core-updates
Conflicts: gnu/packages/ruby.scm
Diffstat (limited to 'guix/build/po.scm')
-rw-r--r--guix/build/po.scm22
1 files changed, 16 insertions, 6 deletions
diff --git a/guix/build/po.scm b/guix/build/po.scm
index 47ff67541c..eb9690ad1a 100644
--- a/guix/build/po.scm
+++ b/guix/build/po.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu>
+;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -19,7 +20,6 @@
(define-module (guix build po)
#:use-module (ice-9 match)
#:use-module (ice-9 peg)
- #:use-module (ice-9 regex)
#:use-module (ice-9 textual-ports)
#:export (read-po-file))
@@ -41,12 +41,22 @@
(and (ignore "\"") (* str-chr) (ignore "\"")
(? (and (ignore (* whitespace)) content))))
+(define (interpret-newline-escape str)
+ "Replace '\\n' sequences in STR with a newline character."
+ (let loop ((str str)
+ (result '()))
+ (match (string-contains str "\\n")
+ (#f (string-concatenate-reverse (cons str result)))
+ (index
+ (let ((prefix (string-take str index)))
+ (loop (string-drop str (+ 2 index))
+ (append (list "\n" prefix) result)))))))
+
(define (parse-tree->assoc parse-tree)
"Converts a po PARSE-TREE to an association list."
- (define regex (make-regexp "\\\\n"))
(match parse-tree
- ('() '())
- ((entry parse-tree ...)
+ (() '())
+ ((entry . parse-tree)
(match entry
((? string? entry)
(parse-tree->assoc parse-tree))
@@ -57,8 +67,8 @@
(('entry ('msgid msgid) 'msgstr)
(parse-tree->assoc parse-tree))
(('entry ('msgid msgid) ('msgstr msgstr))
- (acons (regexp-substitute/global #f regex msgid 'pre "\n" 'post)
- (regexp-substitute/global #f regex msgstr 'pre "\n" 'post)
+ (acons (interpret-newline-escape msgid)
+ (interpret-newline-escape msgstr)
(parse-tree->assoc parse-tree)))))))
(define (read-po-file port)