<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Parsing on Nalar</title>
    <link>https://nalar.dev/tags/parsing/</link>
    <description>Recent content in Parsing on Nalar</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Sun, 13 Sep 2026 00:00:00 +0700</lastBuildDate>
    <atom:link href="https://nalar.dev/tags/parsing/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Remove Explicit Suffixes with strings.CutSuffix in Go</title>
      <link>https://nalar.dev/remove-explicit-suffixes-with-strings-cutsuffix-in-go/</link>
      <pubDate>Sun, 13 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/remove-explicit-suffixes-with-strings-cutsuffix-in-go/</guid>
      <description>&lt;p&gt;&lt;code&gt;strings.CutSuffix&lt;/code&gt; removes one exact trailing string and reports whether that suffix was present. The boolean result is the key distinction from operations that only return transformed text: callers can keep suffix recognition separate from the remaining content.&lt;/p&gt;&#xA;&lt;div&#xA;  x-data=&#34;{ code: $el.querySelector(&#39;code&#39;).innerText, copied: false }&#34;&#xA;  class=&#34;code-block group relative my-6 overflow-hidden rounded-xl border border-line bg-surface-muted dark:border-night-line dark:bg-night-surface&#34;&gt;&#xA;  &lt;button&#xA;    type=&#34;button&#34;&#xA;    @click=&#34;navigator.clipboard.writeText(code); copied = true; setTimeout(() =&gt; copied = false, 1600)&#34;&#xA;    class=&#34;absolute right-3 top-3 z-10 rounded-lg border border-line-strong bg-surface px-2 py-1 font-mono text-[0.65rem] text-muted opacity-0 transition group-hover:opacity-100 hover:bg-ink hover:text-white dark:border-night-line dark:bg-night dark:text-night-muted dark:hover:bg-white dark:hover:text-ink&#34;&gt;&#xA;    &lt;span x-text=&#34;copied ? &#39;Copied&#39; : &#39;Copy&#39;&#34;&gt;&lt;/span&gt;&#xA;  &lt;/button&gt;&#xA;  &#xA;  &lt;div class=&#34;overflow-x-auto p-4 text-sm leading-6 [&amp;_pre]:!m-0 [&amp;_pre]:!bg-transparent [&amp;_pre]:!p-0 [&amp;_code]:font-mono&#34;&gt;&#xA;    &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;base, found := strings.CutSuffix(name, &lt;span style=&#34;font-style:italic&#34;&gt;&amp;#34;.json&amp;#34;&lt;/span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/div&gt;&#xA;&lt;p&gt;If &lt;code&gt;name&lt;/code&gt; ends in &lt;code&gt;.json&lt;/code&gt;, &lt;code&gt;base&lt;/code&gt; contains the preceding text and &lt;code&gt;found&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;. Otherwise, &lt;code&gt;base&lt;/code&gt; is the original string and &lt;code&gt;found&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt;. The operation does not scan for a matching fragment in the middle and does not repeatedly strip the suffix.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Split Once with strings.Cut in Go</title>
      <link>https://nalar.dev/split-once-with-strings-cut-in-go/</link>
      <pubDate>Sun, 13 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/split-once-with-strings-cut-in-go/</guid>
      <description>&lt;p&gt;&lt;code&gt;strings.Cut&lt;/code&gt; separates a string around the first occurrence of a delimiter and reports whether that delimiter was present. That three-result contract matters in parsers where a missing separator is different from a separator followed by an empty value.&lt;/p&gt;&#xA;&lt;div&#xA;  x-data=&#34;{ code: $el.querySelector(&#39;code&#39;).innerText, copied: false }&#34;&#xA;  class=&#34;code-block group relative my-6 overflow-hidden rounded-xl border border-line bg-surface-muted dark:border-night-line dark:bg-night-surface&#34;&gt;&#xA;  &lt;button&#xA;    type=&#34;button&#34;&#xA;    @click=&#34;navigator.clipboard.writeText(code); copied = true; setTimeout(() =&gt; copied = false, 1600)&#34;&#xA;    class=&#34;absolute right-3 top-3 z-10 rounded-lg border border-line-strong bg-surface px-2 py-1 font-mono text-[0.65rem] text-muted opacity-0 transition group-hover:opacity-100 hover:bg-ink hover:text-white dark:border-night-line dark:bg-night dark:text-night-muted dark:hover:bg-white dark:hover:text-ink&#34;&gt;&#xA;    &lt;span x-text=&#34;copied ? &#39;Copied&#39; : &#39;Copy&#39;&#34;&gt;&lt;/span&gt;&#xA;  &lt;/button&gt;&#xA;  &#xA;  &lt;div class=&#34;overflow-x-auto p-4 text-sm leading-6 [&amp;_pre]:!m-0 [&amp;_pre]:!bg-transparent [&amp;_pre]:!p-0 [&amp;_code]:font-mono&#34;&gt;&#xA;    &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;before, after, found := strings.Cut(input, &lt;span style=&#34;font-style:italic&#34;&gt;&amp;#34;=&amp;#34;&lt;/span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/div&gt;&#xA;&lt;p&gt;When the separator exists, &lt;code&gt;before&lt;/code&gt; contains the text preceding its first occurrence and &lt;code&gt;after&lt;/code&gt; contains the remainder. When it does not exist, the function returns the original string, an empty second string, and &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Split Text with Custom Rune Boundaries Using strings.FieldsFunc in Go</title>
      <link>https://nalar.dev/split-text-with-custom-rune-boundaries-using-strings-fieldsfunc/</link>
      <pubDate>Sun, 13 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/split-text-with-custom-rune-boundaries-using-strings-fieldsfunc/</guid>
      <description>&lt;p&gt;&lt;code&gt;strings.FieldsFunc&lt;/code&gt; treats selected Unicode code points as boundaries and returns the non-empty text between them. That behavior fits inputs where separators belong to a class rather than one fixed substring: commas and semicolons, several punctuation marks, or any rune accepted by a deterministic predicate.&lt;/p&gt;&#xA;&lt;div&#xA;  x-data=&#34;{ code: $el.querySelector(&#39;code&#39;).innerText, copied: false }&#34;&#xA;  class=&#34;code-block group relative my-6 overflow-hidden rounded-xl border border-line bg-surface-muted dark:border-night-line dark:bg-night-surface&#34;&gt;&#xA;  &lt;button&#xA;    type=&#34;button&#34;&#xA;    @click=&#34;navigator.clipboard.writeText(code); copied = true; setTimeout(() =&gt; copied = false, 1600)&#34;&#xA;    class=&#34;absolute right-3 top-3 z-10 rounded-lg border border-line-strong bg-surface px-2 py-1 font-mono text-[0.65rem] text-muted opacity-0 transition group-hover:opacity-100 hover:bg-ink hover:text-white dark:border-night-line dark:bg-night dark:text-night-muted dark:hover:bg-white dark:hover:text-ink&#34;&gt;&#xA;    &lt;span x-text=&#34;copied ? &#39;Copied&#39; : &#39;Copy&#39;&#34;&gt;&lt;/span&gt;&#xA;  &lt;/button&gt;&#xA;  &#xA;  &lt;div class=&#34;overflow-x-auto p-4 text-sm leading-6 [&amp;_pre]:!m-0 [&amp;_pre]:!bg-transparent [&amp;_pre]:!p-0 [&amp;_code]:font-mono&#34;&gt;&#xA;    &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;fields := strings.FieldsFunc(input, &lt;span style=&#34;font-weight:bold&#34;&gt;func&lt;/span&gt;(r &lt;span style=&#34;&#34;&gt;rune&lt;/span&gt;) &lt;span style=&#34;&#34;&gt;bool&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;font-weight:bold&#34;&gt;return&lt;/span&gt; r == &lt;span style=&#34;font-style:italic&#34;&gt;&amp;#39;,&amp;#39;&lt;/span&gt; || r == &lt;span style=&#34;font-style:italic&#34;&gt;&amp;#39;;&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;})&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/div&gt;&#xA;&lt;p&gt;For &lt;code&gt;alpha,,beta;gamma;&lt;/code&gt;, the result is &lt;code&gt;[]string{&amp;quot;alpha&amp;quot;, &amp;quot;beta&amp;quot;, &amp;quot;gamma&amp;quot;}&lt;/code&gt;. Consecutive matching runes form a boundary region, and matching runes at either edge do not produce empty elements.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
