From 26339a4d53c35596fbc0d697c8678debd6c81f48 Mon Sep 17 00:00:00 2001 From: "Kamaraju S. Kusumanchi" Date: Wed, 8 Oct 2025 20:43:46 -0400 Subject: [PATCH 1/5] filter out comments --- helper.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/helper.php b/helper.php index 6818802..271e36f 100644 --- a/helper.php +++ b/helper.php @@ -151,6 +151,23 @@ public static function loadContent($file) */ public static function prepareData($content, $opt) { + // Pattern explanation: + // / - Start delimiter + // ^ - Start of line (due to m-modifier) + // \s* - Match zero or more whitespace characters + // # - Match the literal hash symbol + // .* - Match any character until... + // \R - ...the next newline sequence (universal line break) + // /m - End delimiter, with 'm' (multiline) modifier + + // This replaces lines starting with '#' (even with leading whitespace) + // and the trailing newline with an empty string, effectively removing the line. + $content = preg_replace('/^\s*#.*\R/m', '', $content); + + // Remove any trailing empty lines that might have resulted from the replacement. + // This is to handle the scenario where the last line of the file is a comment. + $content = trim($content); + $data = []; // get the first row - it will define the structure From 31db88a0df0079737e94ec8a3ddafb119650c107 Mon Sep 17 00:00:00 2001 From: "Kamaraju S. Kusumanchi" Date: Wed, 8 Oct 2025 21:05:34 -0400 Subject: [PATCH 2/5] handle the case where last line is a comment --- helper.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/helper.php b/helper.php index 271e36f..3e4a73d 100644 --- a/helper.php +++ b/helper.php @@ -152,20 +152,22 @@ public static function loadContent($file) public static function prepareData($content, $opt) { // Pattern explanation: - // / - Start delimiter - // ^ - Start of line (due to m-modifier) - // \s* - Match zero or more whitespace characters - // # - Match the literal hash symbol - // .* - Match any character until... - // \R - ...the next newline sequence (universal line break) - // /m - End delimiter, with 'm' (multiline) modifier + // / - Start delimiter + // ^ - Start of line (due to m-modifier) + // \s* - Match zero or more whitespace characters + // # - Match the literal hash symbol + // .* - Match any character until... + // (\R|$) - ...the next newline sequence (universal line break) OR the + // end of the string ($) to ensure the last line is caught. + // /m - End delimiter, with 'm' (multiline) modifier + $comment_pattern = '/^\s*#.*(\R|$)/m' // This replaces lines starting with '#' (even with leading whitespace) // and the trailing newline with an empty string, effectively removing the line. - $content = preg_replace('/^\s*#.*\R/m', '', $content); + $content = preg_replace($comment_pattern, '', $content); // Remove any trailing empty lines that might have resulted from the replacement. - // This is to handle the scenario where the last line of the file is a comment. + // Strictly speaking, this is not necessary but just adding it for safety. $content = trim($content); $data = []; From cbddcb6cc4fa3e1ce0159f569047ef586d13f1f8 Mon Sep 17 00:00:00 2001 From: "Kamaraju S. Kusumanchi" Date: Wed, 8 Oct 2025 21:08:40 -0400 Subject: [PATCH 3/5] fix syntax mistake --- helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper.php b/helper.php index 3e4a73d..f22f321 100644 --- a/helper.php +++ b/helper.php @@ -160,7 +160,7 @@ public static function prepareData($content, $opt) // (\R|$) - ...the next newline sequence (universal line break) OR the // end of the string ($) to ensure the last line is caught. // /m - End delimiter, with 'm' (multiline) modifier - $comment_pattern = '/^\s*#.*(\R|$)/m' + $comment_pattern = '/^\s*#.*(\R|$)/m'; // This replaces lines starting with '#' (even with leading whitespace) // and the trailing newline with an empty string, effectively removing the line. From 52585a420c27ccda254f6d45b3a1df7b922c9401 Mon Sep 17 00:00:00 2001 From: "Kamaraju S. Kusumanchi" Date: Wed, 8 Oct 2025 21:12:17 -0400 Subject: [PATCH 4/5] convert tabs to spaces --- helper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/helper.php b/helper.php index f22f321..0cf2fda 100644 --- a/helper.php +++ b/helper.php @@ -157,17 +157,17 @@ public static function prepareData($content, $opt) // \s* - Match zero or more whitespace characters // # - Match the literal hash symbol // .* - Match any character until... - // (\R|$) - ...the next newline sequence (universal line break) OR the - // end of the string ($) to ensure the last line is caught. + // (\R|$) - ...the next newline sequence (universal line break) OR the + // end of the string ($) to ensure the last line is caught. // /m - End delimiter, with 'm' (multiline) modifier - $comment_pattern = '/^\s*#.*(\R|$)/m'; + $comment_pattern = '/^\s*#.*(\R|$)/m'; // This replaces lines starting with '#' (even with leading whitespace) // and the trailing newline with an empty string, effectively removing the line. $content = preg_replace($comment_pattern, '', $content); // Remove any trailing empty lines that might have resulted from the replacement. - // Strictly speaking, this is not necessary but just adding it for safety. + // Strictly speaking, this is not necessary but just adding it for safety. $content = trim($content); $data = []; From 5480937a4ef9e92b3882c33cd8aa6dab78a9fb99 Mon Sep 17 00:00:00 2001 From: "Kamaraju S. Kusumanchi" Date: Wed, 8 Oct 2025 21:21:41 -0400 Subject: [PATCH 5/5] Fix comments --- helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper.php b/helper.php index 0cf2fda..df0f5df 100644 --- a/helper.php +++ b/helper.php @@ -163,7 +163,7 @@ public static function prepareData($content, $opt) $comment_pattern = '/^\s*#.*(\R|$)/m'; // This replaces lines starting with '#' (even with leading whitespace) - // and the trailing newline with an empty string, effectively removing the line. + // with an empty string, effectively removing the line. $content = preg_replace($comment_pattern, '', $content); // Remove any trailing empty lines that might have resulted from the replacement.