ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:71658] [Ruby trunk - Feature #11735] [Open] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
@ 2015-11-24 19:36 ` s
  2015-11-24 20:40   ` [ruby-core:71663] " Eric Wong
  2015-11-24 19:38 ` [ruby-core:71659] [Ruby trunk - Feature #11735] " s
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 14+ messages in thread
From: s @ 2015-11-24 19:36 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been reported by Prem Sichanugrist.

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:71659] [Ruby trunk - Feature #11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
  2015-11-24 19:36 ` [ruby-core:71658] [Ruby trunk - Feature #11735] [Open] Porting String#squish and String#squish! from Ruby on Rails' Active Support s
@ 2015-11-24 19:38 ` s
  2015-11-24 19:42 ` [ruby-core:71660] " s
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: s @ 2015-11-24 19:38 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by Prem Sichanugrist.


I also just created a GitHub PR in case that will be easier to give feedback to the code: https://github.com/ruby/ruby/pull/1113

Thank you,
Prem

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-55063

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:71660] [Ruby trunk - Feature #11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
  2015-11-24 19:36 ` [ruby-core:71658] [Ruby trunk - Feature #11735] [Open] Porting String#squish and String#squish! from Ruby on Rails' Active Support s
  2015-11-24 19:38 ` [ruby-core:71659] [Ruby trunk - Feature #11735] " s
@ 2015-11-24 19:42 ` s
  2015-11-25  4:20 ` [ruby-core:71676] " nobu
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: s @ 2015-11-24 19:42 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by Prem Sichanugrist.

Description updated

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-55064

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:71663] Re: [Ruby trunk - Feature #11735] [Open] Porting String#squish and String#squish! from Ruby on Rails' Active Support
  2015-11-24 19:36 ` [ruby-core:71658] [Ruby trunk - Feature #11735] [Open] Porting String#squish and String#squish! from Ruby on Rails' Active Support s
@ 2015-11-24 20:40   ` Eric Wong
  0 siblings, 0 replies; 14+ messages in thread
From: Eric Wong @ 2015-11-24 20:40 UTC (permalink / raw)
  To: Ruby developers

> +static VALUE
> +rb_str_squish_bang(VALUE str)
> +{
> +    static const char before_regex_source[] = "\\A[[:space:]]+";
> +    static const char after_regex_source[] = "[[:space:]]+\\z";
> +    static const char between_regex_source[] = "[[:space:]]+";
> +    VALUE before_argv[] = {
> +        rb_reg_new(before_regex_source, sizeof before_regex_source - 1, 0),
> +        rb_str_new_cstr("")
> +    };
> +    VALUE after_argv[] = {
> +        rb_reg_new(after_regex_source, sizeof after_regex_source - 1, 0),
> +        rb_str_new_cstr("")
> +    };
> +    VALUE between_argv[] = {
> +        rb_reg_new(between_regex_source, sizeof between_regex_source - 1, 0),
> +        rb_str_new_cstr(" ")
> +    };

You could memoize these Regexps as static variables and use
rb_gc_register_mark_object to keep them around so GC won't eat them.
Allocating 3 regexps and 3 strings every call seems like a waste.
You may also use the same

Writing the equivalent Ruby code would only allocate the Regexps once.

You can also auto-dedupe "" and  " " strings with the magic
"frozen_string_literal: true" comment in Ruby or
rb_fstring_cstr function in C.

> By the way, this is my first patch and my first time writing something
> in C, so there might be something that does not look right to you.
> I'll happy to revise this patch (and learn about C in the process!)
> from your feedback.

No worries; but personally (not speaking for the rest of ruby-core);
I would prefer we use prelude.rb more and implement more things in Ruby
rather than C.



Also (definitely not speaking for anybody else in ruby-core);
but the Redmine <-> ruby-core ML integration is the only reason
I've been willing to participate in Ruby development.  I'm not touching
proprietary websites or running any GUI/JavaScript at all to work on
Ruby or any other Free Software.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:71676] [Ruby trunk - Feature #11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2015-11-24 19:42 ` [ruby-core:71660] " s
@ 2015-11-25  4:20 ` nobu
  2015-11-25 17:03 ` [ruby-core:71685] " deivid.rodriguez
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: nobu @ 2015-11-25  4:20 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by Nobuyoshi Nakada.

Description updated

First, indented heredoc will be achieved by [Feature #9098], this will not be needed.

Second, `squish!` feels to return `nil` if no white spaces, to me, like as `sub!` and so on.

Last, it's prohibited in C89 to initialize an aggregate type by dynamic values.


----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-55078

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~ruby
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~ruby
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:71685] [Ruby trunk - Feature #11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2015-11-25  4:20 ` [ruby-core:71676] " nobu
@ 2015-11-25 17:03 ` deivid.rodriguez
  2015-12-07  7:50 ` [ruby-core:71890] " ko1
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: deivid.rodriguez @ 2015-11-25 17:03 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by David Rodríguez.


I don't think the two features are the same, and would find both of them useful.

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-55089

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~ruby
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~ruby
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:71890] [Ruby trunk - Feature #11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2015-11-25 17:03 ` [ruby-core:71685] " deivid.rodriguez
@ 2015-12-07  7:50 ` ko1
  2015-12-07  7:51 ` [ruby-core:71891] " nobu
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: ko1 @ 2015-12-07  7:50 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by Koichi Sasada.

Assignee set to Yukihiro Matsumoto

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-55296

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~ruby
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~ruby
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:71891] [Ruby trunk - Feature #11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2015-12-07  7:50 ` [ruby-core:71890] " ko1
@ 2015-12-07  7:51 ` nobu
  2015-12-07 14:19 ` [ruby-core:71906] " s
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: nobu @ 2015-12-07  7:51 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by Nobuyoshi Nakada.


https://github.com/ruby/ruby/compare/trunk...nobu:feature/11735-squish

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-55297

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~ruby
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~ruby
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:71906] [Ruby trunk - Feature #11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2015-12-07  7:51 ` [ruby-core:71891] " nobu
@ 2015-12-07 14:19 ` s
  2016-05-18  1:22 ` [ruby-core:75589] [Ruby trunk Feature#11735] " shyouhei
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: s @ 2015-12-07 14:19 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by Prem Sichanugrist.


nobu's patch seems to be the better way to implement this feature without having to use regular expression. Much more efficient.

I guess I should try to think outside the box the next time I try to write something in C.

+1 to nobu's patch. Thank you for your hard work.

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-55310

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~ruby
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~ruby
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:75589] [Ruby trunk Feature#11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2015-12-07 14:19 ` [ruby-core:71906] " s
@ 2016-05-18  1:22 ` shyouhei
  2016-05-19 17:57 ` [ruby-core:75616] " amd
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: shyouhei @ 2016-05-18  1:22 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by Shyouhei Urabe.


We looked at it on yesterday's developer meeting but didn't reach a consensus.  This might be because the attendees are mostly Hanzi culture residents (they treat newlines and spaces differently).  This doesn't mean an immediate NG but frankly, we need to study real-world use cases more.

Note #1: recent (2.3+) ruby has squiggly heredoc ("<<~").  This can save someone who originally used squish.

Note #2: as we discuss, I reached a conclusion that squish over SQL is dangerous.  It can destroy SQL's string literals with spaces.

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-58723

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~ruby
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~ruby
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:75616] [Ruby trunk Feature#11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2016-05-18  1:22 ` [ruby-core:75589] [Ruby trunk Feature#11735] " shyouhei
@ 2016-05-19 17:57 ` amd
  2016-05-20  2:38 ` [ruby-core:75631] " shyouhei
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: amd @ 2016-05-19 17:57 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by Adam Doppelt.


It would be great to include squish in String. I've been writing production Ruby code for years and I often pull in ActiveSupport just to get squish.

Getting input from a user? squish
Cleaning up an iffy array.join? squish
Pulling data from a web crawl? squish
Normalizing concatenated data? squish

Squish squish squish. 60k hits on github for Ruby squish. Just squish it. Squish it into core, please.


----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-58748

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~ruby
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~ruby
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:75631] [Ruby trunk Feature#11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2016-05-19 17:57 ` [ruby-core:75616] " amd
@ 2016-05-20  2:38 ` shyouhei
  2016-06-23 17:33 ` [ruby-core:76120] " amd
  2016-06-24  8:02 ` [ruby-core:76134] " shyouhei
  12 siblings, 0 replies; 14+ messages in thread
From: shyouhei @ 2016-05-20  2:38 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by Shyouhei Urabe.


Adam Doppelt wrote:
> Getting input from a user? squish

I guess you have never had a user from CJKV cultures.

> Cleaning up an iffy array.join? squish

This is a huge NO.  It destroys JSON.

> Pulling data from a web crawl? squish

Also NO.  It destroys &lt;pre&gt;.

> Normalizing concatenated data? squish

This could be OK depending on the "normalization" you want.

> Squish squish squish. 60k hits on github for Ruby squish. Just squish it. Squish it into core, please.

I had no pro et contra to the proposal until now.  From what you said I started thinking squish can be a bad smell of indiscreet data treatment.

I hope I'm wrong.

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-58760

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~ruby
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~ruby
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:76120] [Ruby trunk Feature#11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2016-05-20  2:38 ` [ruby-core:75631] " shyouhei
@ 2016-06-23 17:33 ` amd
  2016-06-24  8:02 ` [ruby-core:76134] " shyouhei
  12 siblings, 0 replies; 14+ messages in thread
From: amd @ 2016-06-23 17:33 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by Adam Doppelt.


Shyouhei Urabe wrote:
> I had no pro et contra to the proposal until now.  From what you said I started thinking squish can be a bad smell of indiscreet data treatment.

I think you're missing the point here. Squish is used to cleanup whitespace. If you want to preserve whitespace, don't call it. There are many, many, many (many) situations where cleaning up whitespace is desirable and squish is perfect.

Yes, I actually need to destroy newlines, smash spaces together, and annihilate <pre> tags. This is incredibly common. That's why I use squish. If I didn't want to do those things I would not use squish.

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-59324

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~ruby
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~ruby
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:76134] [Ruby trunk Feature#11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
       [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2016-06-23 17:33 ` [ruby-core:76120] " amd
@ 2016-06-24  8:02 ` shyouhei
  12 siblings, 0 replies; 14+ messages in thread
From: shyouhei @ 2016-06-24  8:02 UTC (permalink / raw)
  To: ruby-core

Issue #11735 has been updated by Shyouhei Urabe.


I don't stop you to do what you want.

But you are requesting it into core.  There are so many miserably misused APIs around the world.  Isn't it just another example of such thing?  Isn't it "too easy to fail"?  For instance is it OK say that applying this method to user input wont introduce SQL injection or that sort of things?

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-59339

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~ruby
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~ruby
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-06-24  7:27 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
2015-11-24 19:36 ` [ruby-core:71658] [Ruby trunk - Feature #11735] [Open] Porting String#squish and String#squish! from Ruby on Rails' Active Support s
2015-11-24 20:40   ` [ruby-core:71663] " Eric Wong
2015-11-24 19:38 ` [ruby-core:71659] [Ruby trunk - Feature #11735] " s
2015-11-24 19:42 ` [ruby-core:71660] " s
2015-11-25  4:20 ` [ruby-core:71676] " nobu
2015-11-25 17:03 ` [ruby-core:71685] " deivid.rodriguez
2015-12-07  7:50 ` [ruby-core:71890] " ko1
2015-12-07  7:51 ` [ruby-core:71891] " nobu
2015-12-07 14:19 ` [ruby-core:71906] " s
2016-05-18  1:22 ` [ruby-core:75589] [Ruby trunk Feature#11735] " shyouhei
2016-05-19 17:57 ` [ruby-core:75616] " amd
2016-05-20  2:38 ` [ruby-core:75631] " shyouhei
2016-06-23 17:33 ` [ruby-core:76120] " amd
2016-06-24  8:02 ` [ruby-core:76134] " shyouhei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).