Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unwrite() to CodeWriter to help with CSVs #1038

Merged
merged 1 commit into from
Jan 7, 2022
Merged

Conversation

mtdowling
Copy link
Member

It's sometimes easier to deal with comma separated values by just always
throwing a ", " at the end of each element in the list, even for the
last element. The unwrite() method allows you to remove the last text
written to the CodeWriter if it matches a given substring. This
allows, for example, ", " to be "unwritten" to removing the trailing
comma without having to first check if the last text written was a
trailing comma. This is similar to Ruby's chomp() method.

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mtdowling mtdowling requested a review from a team as a code owner January 7, 2022 04:29
It's sometimes easier to deal with comma separated values by just always
throwing a ", " at the end of each element in the list, even for the
last element. The unwrite() method allows you to remove the last text
written to the CodeWriter if it matches a given substring. This
allows, for example, ", " to be "unwritten" to removing the trailing
comma without having to first check if the last text written was a
trailing comma. This is similar to Ruby's chomp() method.
@mtdowling mtdowling merged commit 7932798 into main Jan 7, 2022
@mullermp
Copy link
Contributor

mullermp commented Jan 7, 2022

LGTM. This is also useful for new lines. If we're iterating to code generate methods, we want new lines after each method unless it's the last. Ruby classes might be like

class Foo
  def meth1
  end
              <- new line
  def meth2
  end <-- no new line
end

@mtdowling mtdowling deleted the codewriter-unwrite branch January 7, 2022 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants