From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id E1ECC19E0032 for ; Mon, 7 Dec 2015 22:47:46 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 123ACB5D8C3 for ; Mon, 7 Dec 2015 23:19:24 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id B215518CC7D1 for ; Mon, 7 Dec 2015 23:19:24 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 070A012045C; Mon, 7 Dec 2015 23:19:23 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id 30C8C12043B for ; Mon, 7 Dec 2015 23:19:19 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=yebhLc2+i5g5bByb5QmLP3hXICU=; b=ugSKfuIx3O0qYy1++Z CcBniZ3G+sEoCwr+qrRw5s7Q/xJRpR//mqyxUiu8cX6qLk+y1yduTDrE3+freFM1 EuLxhGKkkd1LBjFKqHLGH51Ml5ryz5NksTzfIDVNblJH4YYPdTmnSbtLncgpf7hF 46mUpQUx8eoKb2LrDFr8JudhU= Received: by filter0498p1mdw1.sendgrid.net with SMTP id filter0498p1mdw1.14341.566595581C 2015-12-07 14:19:04.229623684 +0000 UTC Received: from herokuapp.com (ec2-54-242-81-160.compute-1.amazonaws.com [54.242.81.160]) by ismtpd0005p1iad1.sendgrid.net (SG) with ESMTP id WYA_IJWQTC6OGrGS55Yzfg Mon, 07 Dec 2015 14:19:04.220 +0000 (UTC) Date: Mon, 07 Dec 2015 14:19:04 +0000 From: s@sikac.hu To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 46604 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11735 X-Redmine-Issue-Author: sikachu X-Redmine-Issue-Assignee: matz X-Redmine-Sender: sikachu X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4wwLqcLDLT4ymO7m6zNJZpDNs5XpEeCSWoG1 jHB59xUpl8s1Jpmuyq0s6BiNystnNEOwciY6A6IErgJ8GLbxOIWZIkfJxFxM7i4X7uHhAi0nfJbLlj 9iPiFafMDX+fRXQa+YOBx8YfColoPHoFchqm X-ML-Name: ruby-core X-Mail-Count: 71906 Subject: [ruby-core:71906] [Ruby trunk - Feature #11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "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/