@@ -132,24 +132,25 @@ toBeancountMetadataName name =
132132 Just (c,cs) | T. null cs || not (isBeancountMetadataNameStartChar c) -> T. cons beancountMetadataDummyNameStartChar t
133133 _ -> t
134134
135- -- | Is this a valid character to start a Beancount metadata name (lowercase letter) ?
135+ -- | Is this a valid character to start a Beancount metadata name (lowercase ASCII letter) ?
136136isBeancountMetadataNameStartChar :: Char -> Bool
137- isBeancountMetadataNameStartChar c = isLetter c && islowercase c
137+ isBeancountMetadataNameStartChar = isAsciiLower
138138
139139-- | Dummy valid starting character to prepend to a Beancount metadata name if needed.
140140beancountMetadataDummyNameStartChar :: Char
141141beancountMetadataDummyNameStartChar = ' m'
142142
143- -- | Is this a valid character in the middle of a Beancount metadata name (a lowercase letter, digit, _ or -) ?
143+ -- | Is this a valid character in the middle of a Beancount metadata name (a lowercase ASCII letter, digit, _ or -) ?
144144isBeancountMetadataNameChar :: Char -> Bool
145- isBeancountMetadataNameChar c = (isLetter c && islowercase c) || isDigit c || c `elem` [' _' , ' -' ]
145+ isBeancountMetadataNameChar c = isAsciiLower c || isDigit c || c `elem` [' _' , ' -' ]
146146
147147-- | Convert a character to one or more characters valid inside a Beancount metadata name.
148- -- Letters are lowercased, spaces are converted to dashes, and unsupported characters are encoded as c<HEXBYTES>.
148+ -- ASCII uppercase letters are lowercased, spaces are converted to dashes, and unsupported
149+ -- characters (including non-ASCII letters) are encoded as c<HEXBYTES>.
149150toBeancountMetadataNameChar :: Char -> Text
150151toBeancountMetadataNameChar c
151152 | isBeancountMetadataNameChar c = T. singleton c
152- | isLetter c = T. singleton $ toLower c
153+ | isAsciiUpper c = T. singleton $ toLower c
153154 | isSpace c = " -"
154155 | otherwise = T. pack $ printf " c%x" c
155156
@@ -312,8 +313,6 @@ charToBeancount c = if isSpace c then "-" else printf "C%x" c
312313-- https://hackage.haskell.org/package/base-4.20.0.1/docs/Data-Char.html#v:isUpperCase would be more correct,
313314-- but isn't available till base 4.18/ghc 9.6. isUpper is close enough in practice.
314315isuppercase = isUpper
315- -- same story, presumably
316- islowercase = isLower
317316
318317-- | Is this a valid character to start a Beancount account name part (capital letter or digit) ?
319318isBeancountAccountStartChar :: Char -> Bool
0 commit comments