From 1a91ce5dd025bdc5ca0ab50725ea6dfaf65a14a2 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Fri, 17 May 2024 17:22:51 +0200 Subject: [PATCH] allow commenting lines in json layouts by starting the line with // --- .../keyboard/internal/keyboard_parser/RawKeyboardParser.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/RawKeyboardParser.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/RawKeyboardParser.kt index f108a566..7c47dae9 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/RawKeyboardParser.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/RawKeyboardParser.kt @@ -65,7 +65,7 @@ object RawKeyboardParser { * codes of multi_text_key not used, only the label * (currently) popups is always read to [number, main, relevant] layoutPopupKeys, no choice of which to use or which hint is provided */ - fun parseJsonString(layoutText: String): List> = florisJsonConfig.decodeFromString(layoutText) + fun parseJsonString(layoutText: String): List> = florisJsonConfig.decodeFromString(layoutText.stripCommentLines()) /** Parse simple layouts, defined only as rows of (normal) keys with popup keys. */ fun parseSimpleString(layoutText: String): List> { @@ -166,6 +166,10 @@ object RawKeyboardParser { } } + // allow commenting lines by starting them with "//" + private fun String.stripCommentLines(): String = + split("\n").filterNot { it.startsWith("//") }.joinToString("\n") + /* * Copyright (C) 2021 Patrick Goldinger * modified