diff --git a/spec/std/base64_spec.cr b/spec/std/base64_spec.cr index 567340d6fa38..300498120bc6 100644 --- a/spec/std/base64_spec.cr +++ b/spec/std/base64_spec.cr @@ -169,13 +169,13 @@ describe "Base64" do "Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4gQ3J5c3RhbA==" end it "with spec symbols" do - s = String.build { |b| (160..179).each { |i| b << i.chr } } + s = String.build { |buf| (160..179).each { |i| buf << i.chr } } se = "wqDCocKiwqPCpMKlwqbCp8KowqnCqsKrwqzCrcKuwq/CsMKxwrLCsw==" assert_prints base64_strict_encode(s), se end it "encode to stream returns number of written characters" do - s = String.build { |b| (160..179).each { |i| b << i.chr } } + s = String.build { |buf| (160..179).each { |i| buf << i.chr } } io = IO::Memory.new Base64.strict_encode(s, io).should eq(56) end @@ -183,13 +183,13 @@ describe "Base64" do describe "urlsafe" do it "work" do - s = String.build { |b| (160..179).each { |i| b << i.chr } } + s = String.build { |buf| (160..179).each { |i| buf << i.chr } } se = "wqDCocKiwqPCpMKlwqbCp8KowqnCqsKrwqzCrcKuwq_CsMKxwrLCsw==" assert_prints base64_urlsafe_encode(s), se end it "encode to stream returns number of written characters" do - s = String.build { |b| (160..179).each { |i| b << i.chr } } + s = String.build { |buf| (160..179).each { |i| buf << i.chr } } io = IO::Memory.new Base64.urlsafe_encode(s, io).should eq(56) end diff --git a/spec/std/io/buffered_spec.cr b/spec/std/io/buffered_spec.cr index d8ef8ff3b979..1fd7990166ed 100644 --- a/spec/std/io/buffered_spec.cr +++ b/spec/std/io/buffered_spec.cr @@ -220,10 +220,10 @@ describe "IO::Buffered" do end it "reads more than the buffer's internal capacity" do - s = String.build do |str| + s = String.build do |buf| 900.times do 10.times do |i| - str << ('a' + i) + buf << ('a' + i) end end end @@ -241,10 +241,10 @@ describe "IO::Buffered" do end it "writes more than the buffer's internal capacity" do - s = String.build do |str| + s = String.build do |buf| 900.times do 10.times do |i| - str << ('a' + i) + buf << ('a' + i) end end end diff --git a/spec/std/io/io_spec.cr b/spec/std/io/io_spec.cr index ac51d4bddaea..a569e0be32cf 100644 --- a/spec/std/io/io_spec.cr +++ b/spec/std/io/io_spec.cr @@ -708,10 +708,10 @@ describe IO do end it "skips invalid byte sequences" do - string = String.build do |str| - str.write "好".encode("EUC-JP") - str.write_byte 255_u8 - str.write "是".encode("EUC-JP") + string = String.build do |io| + io.write "好".encode("EUC-JP") + io.write_byte 255_u8 + io.write "是".encode("EUC-JP") end io = SimpleIOMemory.new(string) io.set_encoding("EUC-JP", invalid: :skip) diff --git a/spec/std/string_spec.cr b/spec/std/string_spec.cr index 905930463cfc..9db7e3c4ce82 100644 --- a/spec/std/string_spec.cr +++ b/spec/std/string_spec.cr @@ -1903,8 +1903,8 @@ describe "String" do end it "scans using $~" do - str = String.build do |str| - "fooxooo".scan(/(o+)/) { str << $1 } + str = String.build do |io| + "fooxooo".scan(/(o+)/) { io << $1 } end str.should eq("ooooo") end diff --git a/spec/std/yaml/serialization_spec.cr b/spec/std/yaml/serialization_spec.cr index b65667d8a504..bccbbd35c298 100644 --- a/spec/std/yaml/serialization_spec.cr +++ b/spec/std/yaml/serialization_spec.cr @@ -652,8 +652,8 @@ describe "YAML serialization" do end it "writes to a stream" do - string = String.build do |str| - %w(a b c).to_yaml(str) + string = String.build do |io| + %w(a b c).to_yaml(io) end string.should eq("---\n- a\n- b\n- c\n") end diff --git a/spec/std/yaml/yaml_spec.cr b/spec/std/yaml/yaml_spec.cr index 996b74f06716..e52496915046 100644 --- a/spec/std/yaml/yaml_spec.cr +++ b/spec/std/yaml/yaml_spec.cr @@ -157,8 +157,8 @@ describe "YAML" do end it "writes YAML to a stream" do - string = String.build do |str| - YAML.dump(%w(1 2 3), str) + string = String.build do |io| + YAML.dump(%w(1 2 3), io) end string.should eq(%(---\n- "1"\n- "2"\n- "3"\n)) end diff --git a/src/compiler/crystal/codegen/ast.cr b/src/compiler/crystal/codegen/ast.cr index 816958844dd9..93e5ab32ac04 100644 --- a/src/compiler/crystal/codegen/ast.cr +++ b/src/compiler/crystal/codegen/ast.cr @@ -11,53 +11,53 @@ module Crystal property? abi_info = false def mangled_name(program, self_type) - name = String.build do |str| - str << '*' + name = String.build do |io| + io << '*' if owner = @owner if owner.metaclass? - self_type.instance_type.llvm_name(str) + self_type.instance_type.llvm_name(io) if original_owner != self_type - str << '@' - original_owner.instance_type.llvm_name(str) + io << '@' + original_owner.instance_type.llvm_name(io) end - str << "::" + io << "::" elsif !owner.is_a?(Crystal::Program) - self_type.llvm_name(str) + self_type.llvm_name(io) if original_owner != self_type - str << '@' - original_owner.llvm_name(str) + io << '@' + original_owner.llvm_name(io) end - str << '#' + io << '#' end end - str << self.name.gsub('@', '.') + io << self.name.gsub('@', '.') next_def = self.next while next_def - str << '\'' + io << '\'' next_def = next_def.next end if args.size > 0 || uses_block_arg? - str << '<' + io << '<' if args.size > 0 args.each_with_index do |arg, i| - str << ", " if i > 0 - arg.type.llvm_name(str) + io << ", " if i > 0 + arg.type.llvm_name(io) end end if uses_block_arg? - str << ", " if args.size > 0 - str << '&' - block_arg.not_nil!.type.llvm_name(str) + io << ", " if args.size > 0 + io << '&' + block_arg.not_nil!.type.llvm_name(io) end - str << '>' + io << '>' end if return_type = @type - str << ':' - return_type.llvm_name(str) + io << ':' + return_type.llvm_name(io) end end diff --git a/src/compiler/crystal/codegen/codegen.cr b/src/compiler/crystal/codegen/codegen.cr index 2c357183ffa5..d7ac8e434dcb 100644 --- a/src/compiler/crystal/codegen/codegen.cr +++ b/src/compiler/crystal/codegen/codegen.cr @@ -2341,14 +2341,14 @@ module Crystal def self.safe_mangling(program, name) if program.has_flag?("windows") - String.build do |str| + String.build do |io| name.each_char do |char| if char.ascii_alphanumeric? || char == '_' - str << char + io << char else - str << '.' - char.ord.to_s(str, 16, upcase: true) - str << '.' + io << '.' + char.ord.to_s(io, 16, upcase: true) + io << '.' end end end diff --git a/src/compiler/crystal/compiler.cr b/src/compiler/crystal/compiler.cr index f32ecd344be1..551b469c7d7c 100644 --- a/src/compiler/crystal/compiler.cr +++ b/src/compiler/crystal/compiler.cr @@ -691,17 +691,17 @@ module Crystal @llvm_mod : LLVM::Module, @output_dir : String, @bc_flags_changed : Bool) @name = "_main" if @name == "" @original_name = @name - @name = String.build do |str| + @name = String.build do |io| @name.each_char do |char| case char when 'a'..'z', '0'..'9', '_' - str << char + io << char when 'A'..'Z' # Because OSX has case insensitive filenames, try to avoid # clash of 'a' and 'A' by using 'A-' for 'A'. - str << char << '-' + io << char << '-' else - str << char.ord + io << char.ord end end end diff --git a/src/compiler/crystal/macros/interpreter.cr b/src/compiler/crystal/macros/interpreter.cr index af76e087ced3..0d45369c83f2 100644 --- a/src/compiler/crystal/macros/interpreter.cr +++ b/src/compiler/crystal/macros/interpreter.cr @@ -157,13 +157,13 @@ module Crystal end def visit(node : StringInterpolation) - @last = StringLiteral.new(String.build do |str| + @last = StringLiteral.new(String.build do |io| node.expressions.each do |exp| if exp.is_a?(StringLiteral) - str << exp.value + io << exp.value else exp.accept self - @last.to_s(str) + @last.to_s(io) end end end) diff --git a/src/compiler/crystal/semantic/call_error.cr b/src/compiler/crystal/semantic/call_error.cr index 5d3061850e2e..2c97a9855313 100644 --- a/src/compiler/crystal/semantic/call_error.cr +++ b/src/compiler/crystal/semantic/call_error.cr @@ -380,13 +380,13 @@ class Crystal::Call end private def raise_no_overload_matches(node, defs, arg_types, inner_exception, &) - error_message = String.build do |str| - yield str + error_message = String.build do |io| + yield io - str.puts - str.puts - str << "Overloads are:" - append_matches(defs, arg_types, str) + io.puts + io.puts + io << "Overloads are:" + append_matches(defs, arg_types, io) end node.raise(error_message, inner_exception) @@ -675,31 +675,31 @@ class Crystal::Call end all_arguments_sizes.uniq!.sort! - raise(String.build do |str| + raise(String.build do |io| if single_message = single_def_error_message(defs, named_args_types) - str << single_message - str << '\n' + io << single_message + io << '\n' else - str << "wrong number of arguments for '" - str << full_name(owner, def_name) - str << "' (given " - str << arg_types.size - str << ", expected " + io << "wrong number of arguments for '" + io << full_name(owner, def_name) + io << "' (given " + io << arg_types.size + io << ", expected " # If we have 2, 3, 4, show it as 2..4 if all_arguments_sizes.size > 1 && all_arguments_sizes.last - all_arguments_sizes.first == all_arguments_sizes.size - 1 - str << all_arguments_sizes.first - str << ".." - str << all_arguments_sizes.last + io << all_arguments_sizes.first + io << ".." + io << all_arguments_sizes.last else - all_arguments_sizes.join str, ", " + all_arguments_sizes.join io, ", " end - str << '+' if min_splat != Int32::MAX - str << ")\n" + io << '+' if min_splat != Int32::MAX + io << ")\n" end - str << "Overloads are:" - append_matches(defs, arg_types, str) + io << "Overloads are:" + append_matches(defs, arg_types, io) end, inner: inner_exception) end diff --git a/src/compiler/crystal/semantic/cleanup_transformer.cr b/src/compiler/crystal/semantic/cleanup_transformer.cr index 70a8ffe63590..f0b010cd31b9 100644 --- a/src/compiler/crystal/semantic/cleanup_transformer.cr +++ b/src/compiler/crystal/semantic/cleanup_transformer.cr @@ -754,11 +754,11 @@ module Crystal end def untyped_expression(node, msg = nil) - ex_msg = String.build do |str| - str << "can't execute `" << node << "` at " << node.location + ex_msg = String.build do |io| + io << "can't execute `" << node << "` at " << node.location if msg - str << ": " - str << msg + io << ": " + io << msg end end diff --git a/src/compiler/crystal/semantic/default_arguments.cr b/src/compiler/crystal/semantic/default_arguments.cr index 013caab3c3aa..2618bdc32488 100644 --- a/src/compiler/crystal/semantic/default_arguments.cr +++ b/src/compiler/crystal/semantic/default_arguments.cr @@ -72,11 +72,11 @@ class Crystal::Def # names that won't clash with local variables defined in the method. named_args_temp_names = Array(String).new(named_args.size) - new_name = String.build do |str| - str << name + new_name = String.build do |io| + io << name named_args.each do |named_arg| - str << ':' - str << named_arg + io << ':' + io << named_arg temp_name = program.new_temp_var_name named_args_temp_names << temp_name diff --git a/src/compiler/crystal/semantic/exception.cr b/src/compiler/crystal/semantic/exception.cr index 359f12ffb882..eea17483e7a0 100644 --- a/src/compiler/crystal/semantic/exception.cr +++ b/src/compiler/crystal/semantic/exception.cr @@ -308,35 +308,35 @@ module Crystal class Program def undefined_class_variable(node, owner, similar_name) - common = String.build do |str| - str << "can't infer the type of class variable '#{node.name}' of #{owner.devirtualize}" + common = String.build do |io| + io << "can't infer the type of class variable '#{node.name}' of #{owner.devirtualize}" if similar_name - str << '\n' - str << "Did you mean '#{similar_name}'?" + io << '\n' + io << "Did you mean '#{similar_name}'?" end end - msg = String.build do |str| - str << common - str << "\n\n" - str << undefined_variable_message("class variable", node.name, owner.devirtualize) + msg = String.build do |io| + io << common + io << "\n\n" + io << undefined_variable_message("class variable", node.name, owner.devirtualize) end node.raise msg end def undefined_instance_variable(node, owner, similar_name) - common = String.build do |str| - str << "can't infer the type of instance variable '#{node.name}' of #{owner.devirtualize}" + common = String.build do |io| + io << "can't infer the type of instance variable '#{node.name}' of #{owner.devirtualize}" if similar_name - str << '\n' - str << "Did you mean '#{similar_name}'?" + io << '\n' + io << "Did you mean '#{similar_name}'?" end end - msg = String.build do |str| - str << common - str << "\n\n" - str << undefined_variable_message("instance variable", node.name, owner.devirtualize) + msg = String.build do |io| + io << common + io << "\n\n" + io << undefined_variable_message("instance variable", node.name, owner.devirtualize) end node.raise msg end diff --git a/src/compiler/crystal/semantic/new.cr b/src/compiler/crystal/semantic/new.cr index de8ae55312a0..63c077fa7b88 100644 --- a/src/compiler/crystal/semantic/new.cr +++ b/src/compiler/crystal/semantic/new.cr @@ -271,11 +271,11 @@ module Crystal splat_index = i i += 1 - name = String.build do |str| - str << "new" + name = String.build do |io| + io << "new" named_args.each do |named_arg| - str << ':' - str << named_arg + io << ':' + io << named_arg # When **opts is expanded for named arguments, we must use internal # names that won't clash with local variables defined in the method. diff --git a/src/compiler/crystal/semantic/semantic_visitor.cr b/src/compiler/crystal/semantic/semantic_visitor.cr index 0b686db9dc40..a2a937e643b4 100644 --- a/src/compiler/crystal/semantic/semantic_visitor.cr +++ b/src/compiler/crystal/semantic/semantic_visitor.cr @@ -534,10 +534,10 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor def check_allowed_in_lib(node, type = node.type.instance_type) unless type.allowed_in_lib? - msg = String.build do |msg| - msg << "only primitive types, pointers, structs, unions, enums and tuples are allowed in lib declarations, not #{type}" - msg << " (did you mean LibC::Int?)" if type == @program.int - msg << " (did you mean LibC::Float?)" if type == @program.float + msg = String.build do |io| + io << "only primitive types, pointers, structs, unions, enums and tuples are allowed in lib declarations, not #{type}" + io << " (did you mean LibC::Int?)" if type == @program.int + io << " (did you mean LibC::Float?)" if type == @program.float end node.raise msg end diff --git a/src/compiler/crystal/syntax/lexer.cr b/src/compiler/crystal/syntax/lexer.cr index 33f991c5fc0f..f5fab3c7c154 100644 --- a/src/compiler/crystal/syntax/lexer.cr +++ b/src/compiler/crystal/syntax/lexer.cr @@ -2183,9 +2183,9 @@ module Crystal end def consume_string_unicode_brace_escape - String.build do |str| + String.build do |io| while true - str << consume_braced_unicode_escape(allow_spaces: true).chr + io << consume_braced_unicode_escape(allow_spaces: true).chr break unless current_char == ' ' end end diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index f2c6bd8ed867..52cd371bf1c0 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -1934,16 +1934,16 @@ module Crystal location = @token.location next_token_skip_space - msg = String.build do |msg| - msg << %[unexpected token: "|", proc literals specify their parameters like this: ->(] + msg = String.build do |io| + io << %[unexpected token: "|", proc literals specify their parameters like this: ->(] if @token.type.ident? - msg << @token.value.to_s << " : Type" + io << @token.value.to_s << " : Type" next_token_skip_space_or_newline - msg << ", ..." if @token.type.op_comma? + io << ", ..." if @token.type.op_comma? else - msg << "param : Type" + io << "param : Type" end - msg << ") { ... }" + io << ") { ... }" end raise msg, location diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index 32168af580e9..edba68b1cca9 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -5005,10 +5005,10 @@ module Crystal before = line[0...middle] after = line[middle..-1] - result = String.build do |str| - str << before - gap.times { str << ' ' } - str << after + result = String.build do |io| + io << before + gap.times { io << ' ' } + io << after end lines[info.line] = result @@ -5059,10 +5059,10 @@ module Crystal comment_line = line[comment_column..-1] gap = max_column - comment_column - result = String.build do |str| - str << source_line - gap.times { str << ' ' } - str << comment_line + result = String.build do |io| + io << source_line + gap.times { io << ' ' } + io << comment_line end result end @@ -5074,12 +5074,12 @@ module Crystal first_line = lines[doc_comment.start_line] sharp_index = first_line.index('#').not_nil! - comment = String.build do |str| + comment = String.build do |io| (doc_comment.start_line..doc_comment.end_line).each do |i| line = lines[i].strip[1..-1] line = line[1..-1] if line[0]? == ' ' - str << line - str << '\n' + io << line + io << '\n' end end @@ -5087,10 +5087,10 @@ module Crystal formatted_comment = Formatter.format(comment) formatted_lines = formatted_comment.lines formatted_lines.map! do |line| - String.build do |str| - sharp_index.times { str << ' ' } - str << "# " - str << line + String.build do |io| + sharp_index.times { io << ' ' } + io << "# " + io << line end end lines[doc_comment.start_line..doc_comment.end_line] = formatted_lines diff --git a/src/crypto/bcrypt/base64.cr b/src/crypto/bcrypt/base64.cr index 01c59f237d62..2db7f44d85fe 100644 --- a/src/crypto/bcrypt/base64.cr +++ b/src/crypto/bcrypt/base64.cr @@ -23,34 +23,34 @@ module Crypto::Bcrypt::Base64 def self.encode(d, len) : String off = 0 - String.build do |str| + String.build do |io| loop do c1 = d[off] & 0xff off += 1 - str << ALPHABET[(c1 >> 2) & 0x3f] + io << ALPHABET[(c1 >> 2) & 0x3f] c1 = (c1 & 0x03) << 4 if off >= len - str << ALPHABET[c1 & 0x3f] + io << ALPHABET[c1 & 0x3f] break end c2 = d[off] & 0xff off += 1 c1 |= (c2 >> 4) & 0x0f - str << ALPHABET[c1 & 0x3f] + io << ALPHABET[c1 & 0x3f] c1 = (c2 & 0x0f) << 2 if off >= len - str << ALPHABET[c1 & 0x3f] + io << ALPHABET[c1 & 0x3f] break end c2 = d[off] & 0xff off += 1 c1 |= (c2 >> 6) & 0x03 - str << ALPHABET[c1 & 0x3f] - str << ALPHABET[c2 & 0x3f] + io << ALPHABET[c1 & 0x3f] + io << ALPHABET[c2 & 0x3f] break if off >= len end diff --git a/src/crystal/elf.cr b/src/crystal/elf.cr index 365d88fb59b0..a4445b42532f 100644 --- a/src/crystal/elf.cr +++ b/src/crystal/elf.cr @@ -105,13 +105,13 @@ module Crystal MASKPROC = 0xf0000000 def short - String.build do |str| - str << 'W' if write? - str << 'A' if alloc? - str << 'X' if execinstr? - str << 'M' if merge? - str << 'S' if strings? - str << 'T' if tls? + String.build do |io| + io << 'W' if write? + io << 'A' if alloc? + io << 'X' if execinstr? + io << 'M' if merge? + io << 'S' if strings? + io << 'T' if tls? end end end diff --git a/src/ecr/processor.cr b/src/ecr/processor.cr index 786879e94273..4bd81cadc9ce 100644 --- a/src/ecr/processor.cr +++ b/src/ecr/processor.cr @@ -15,7 +15,7 @@ module ECR lexer = Lexer.new string token = lexer.next_token - String.build do |str| + String.build do |io| while true case token.type when .string? @@ -24,10 +24,10 @@ module ECR string = suppress_leading_indentation(token, string) - str << buffer_name - str << " << " - string.inspect(str) - str << '\n' + io << buffer_name + io << " << " + string.inspect(io) + io << '\n' when .output? string = token.value line_number = token.line_number @@ -37,12 +37,12 @@ module ECR suppress_trailing_whitespace(token, suppress_trailing) - str << "#(" - append_loc(str, filename, line_number, column_number) - str << string - str << ")#.to_s " - str << buffer_name - str << '\n' + io << "#(" + append_loc(io, filename, line_number, column_number) + io << string + io << ")#.to_s " + io << buffer_name + io << '\n' when .control? string = token.value line_number = token.line_number @@ -52,12 +52,12 @@ module ECR suppress_trailing_whitespace(token, suppress_trailing) - str << "#" - append_loc(str, filename, line_number, column_number) - str << ' ' unless string.starts_with?(' ') - str << string - str << "#" - str << '\n' + io << "#" + append_loc(io, filename, line_number, column_number) + io << ' ' unless string.starts_with?(' ') + io << string + io << "#" + io << '\n' when .eof? break end diff --git a/src/http/formdata/builder.cr b/src/http/formdata/builder.cr index 8011b0e98920..6d019da3ba84 100644 --- a/src/http/formdata/builder.cr +++ b/src/http/formdata/builder.cr @@ -36,10 +36,10 @@ module HTTP::FormData # builder.content_type # => "multipart/form-data; boundary=\"a4VF\"" # ``` def content_type : String - String.build do |str| - str << "multipart/form-data; boundary=\"" - HTTP.quote_string(@boundary, str) - str << '"' + String.build do |io| + io << "multipart/form-data; boundary=\"" + HTTP.quote_string(@boundary, io) + io << '"' end end diff --git a/src/ini.cr b/src/ini.cr index d9cea1c82e82..ce46745e3cbd 100644 --- a/src/ini.cr +++ b/src/ini.cr @@ -67,7 +67,7 @@ module INI # INI.build({"foo" => {"a" => "1"}}, true) # => "[foo]\na = 1\n\n" # ``` def self.build(ini, space : Bool = false) : String - String.build { |str| build str, ini, space } + String.build { |io| build io, ini, space } end # Appends INI data to the given IO. diff --git a/src/io.cr b/src/io.cr index bce6497db606..b734b107a2a1 100644 --- a/src/io.cr +++ b/src/io.cr @@ -552,18 +552,18 @@ abstract class IO # io.gets_to_end # => "" # ``` def gets_to_end : String - String.build do |str| + String.build do |io| if decoder = decoder() while true decoder.read(self) break if decoder.out_slice.empty? - decoder.write(str) + decoder.write(io) end else buffer = uninitialized UInt8[DEFAULT_BUFFER_SIZE] while (read_bytes = read(buffer.to_slice)) > 0 - str.write buffer.to_slice[0, read_bytes] + io.write buffer.to_slice[0, read_bytes] end end end diff --git a/src/io/encoding.cr b/src/io/encoding.cr index 733e6b199168..b8141e8bbde5 100644 --- a/src/io/encoding.cr +++ b/src/io/encoding.cr @@ -184,10 +184,10 @@ class IO # We need to read from the out_slice into a String until we find that byte, # or until we consumed limit bytes - String.build do |str| + String.build do |io1| loop do limit -= @out_slice.size - write str + write io1 read(io) @@ -200,16 +200,16 @@ class IO else index += 1 end - write str, index + write io1, index break else if limit < @out_slice.size - write(str, limit) + write(io1, limit) break end end end - str.chomp!(delimiter) if chomp + io1.chomp!(delimiter) if chomp end end diff --git a/src/json/builder.cr b/src/json/builder.cr index 893970e31f1c..cb1daadb0715 100644 --- a/src/json/builder.cr +++ b/src/json/builder.cr @@ -401,8 +401,8 @@ module JSON # string # => %<{"name":"foo","values":[1,2,3]}> # ``` def self.build(indent = nil, &) - String.build do |str| - build(str, indent) do |json| + String.build do |io| + build(io, indent) do |json| yield json end end diff --git a/src/json/to_json.cr b/src/json/to_json.cr index 18d4df75ec2f..0c682f184543 100644 --- a/src/json/to_json.cr +++ b/src/json/to_json.cr @@ -1,7 +1,7 @@ class Object def to_json : String - String.build do |str| - to_json str + String.build do |io| + to_json io end end @@ -12,8 +12,8 @@ class Object end def to_pretty_json(indent : String = " ") : String - String.build do |str| - to_pretty_json str, indent: indent + String.build do |io| + to_pretty_json io, indent: indent end end diff --git a/src/kernel.cr b/src/kernel.cr index 7bca29cef605..c8eeb20de549 100644 --- a/src/kernel.cr +++ b/src/kernel.cr @@ -405,8 +405,8 @@ end # :ditto: def sprintf(format_string, args : Array | Tuple) : String - String.build(format_string.bytesize) do |str| - String::Formatter(typeof(args)).new(format_string, args, str).format + String.build(format_string.bytesize) do |io| + String::Formatter(typeof(args)).new(format_string, args, io).format end end diff --git a/src/oauth/signature.cr b/src/oauth/signature.cr index 2038243f25fa..48f78ec6a32b 100644 --- a/src/oauth/signature.cr +++ b/src/oauth/signature.cr @@ -8,11 +8,11 @@ struct OAuth::Signature end def key : String - String.build do |str| - URI.encode_www_form @client_shared_secret, str, space_to_plus: false - str << '&' + String.build do |io| + URI.encode_www_form @client_shared_secret, io, space_to_plus: false + io << '&' if token_shared_secret = @token_shared_secret - URI.encode_www_form token_shared_secret, str, space_to_plus: false + URI.encode_www_form token_shared_secret, io, space_to_plus: false end end end @@ -42,20 +42,20 @@ struct OAuth::Signature private def base_string(request, tls, params) host, port = host_and_port(request, tls) - String.build do |str| - str << request.method - str << '&' - str << (tls ? "https" : "http") - str << "%3A%2F%2F" - URI.encode_www_form host, str, space_to_plus: false + String.build do |io| + io << request.method + io << '&' + io << (tls ? "https" : "http") + io << "%3A%2F%2F" + URI.encode_www_form host, io, space_to_plus: false if port - str << "%3A" - str << port + io << "%3A" + io << port end uri_path = request.path.presence || "/" - URI.encode_www_form(uri_path, str, space_to_plus: false) - str << '&' - str << params + URI.encode_www_form(uri_path, io, space_to_plus: false) + io << '&' + io << params end end diff --git a/src/openssl/x509/extension.cr b/src/openssl/x509/extension.cr index b326a35f8309..c668fbae07d3 100644 --- a/src/openssl/x509/extension.cr +++ b/src/openssl/x509/extension.cr @@ -12,9 +12,9 @@ module OpenSSL::X509 end def initialize(nid : Int32, value : String, critical = false) - valstr = String.build do |str| - str << "critical," if critical - str << value + valstr = String.build do |io| + io << "critical," if critical + io << value end @ext = LibCrypto.x509v3_ext_nconf_nid(nil, nil, nid, valstr) raise Error.new("X509V3_EXT_nconf_nid") if @ext.null? diff --git a/src/path.cr b/src/path.cr index 4ec62b39d95d..db721fd5df5f 100644 --- a/src/path.cr +++ b/src/path.cr @@ -419,17 +419,17 @@ struct Path separators = self.separators add_separator_at_end = !remove_final_separator && ends_with_separator? - new_name = String.build do |str| + new_name = String.build do |io| if drive - str << drive.gsub('/', '\\') + io << drive.gsub('/', '\\') reader.pos += drive.bytesize end if root - str << separators[0] + io << separators[0] reader.next_char - dotdot = str.bytesize + dotdot = io.bytesize end - anchor_pos = str.bytesize + anchor_pos = io.bytesize while (char = reader.current_char) != Char::ZERO curr_pos = reader.pos @@ -442,43 +442,43 @@ struct Path elsif char == '.' && reader.next_char == '.' && (reader.pos + 1 == @name.bytesize || separators.includes?(reader.peek_next_char)) # .. element: remove to last / reader.next_char - if str.bytesize > dotdot - str.back 1 - while str.bytesize > dotdot && !separators.includes?((str.buffer + str.bytesize).value.unsafe_chr) - str.back 1 + if io.bytesize > dotdot + io.back 1 + while io.bytesize > dotdot && !separators.includes?((io.buffer + io.bytesize).value.unsafe_chr) + io.back 1 end elsif !root - if str.bytesize > 0 - str << separators[0] + if io.bytesize > 0 + io << separators[0] end - str << ".." - dotdot = str.bytesize + io << ".." + dotdot = io.bytesize end else reader.pos = curr_pos # make sure to reset lookahead used in previous condition # real path element # add slash if needed - if str.bytesize > anchor_pos && !separators.includes?((str.buffer + str.bytesize - 1).value.unsafe_chr) - str << separators[0] + if io.bytesize > anchor_pos && !separators.includes?((io.buffer + io.bytesize - 1).value.unsafe_chr) + io << separators[0] end loop do - str << char + io << char char = reader.next_char break if separators.includes?(char) || char == Char::ZERO end end end - if str.empty? - str << '.' + if io.empty? + io << '.' end - last_char = (str.buffer + str.bytesize - 1).value.unsafe_chr + last_char = (io.buffer + io.bytesize - 1).value.unsafe_chr if add_separator_at_end && !separators.includes?(last_char) - str << separators[0] + io << separators[0] end end diff --git a/src/process/shell.cr b/src/process/shell.cr index e206c6c19a5a..bfde3a107687 100644 --- a/src/process/shell.cr +++ b/src/process/shell.cr @@ -140,7 +140,7 @@ class Process end break unless reader.has_next? - token = String.build do |str| + token = String.build do |io| while reader.has_next? && !reader.current_char.ascii_whitespace? quote = nil if reader.current_char.in?('\'', '"') @@ -152,7 +152,7 @@ class Process break unless reader.has_next? reader.next_char if char == '\\' && quote != '\'' - str << char if quote == '"' + io << char if quote == '"' char = reader.current_char if reader.has_next? reader.next_char @@ -161,7 +161,7 @@ class Process char = '\\' end end - str << char + io << char end if quote @@ -203,7 +203,7 @@ class Process end break unless reader.has_next? - token = String.build do |str| + token = String.build do |io| while true backslash_count = 0 while reader.current_char == '\\' @@ -212,19 +212,19 @@ class Process end if reader.current_char == '"' - (backslash_count // 2).times { str << '\\' } + (backslash_count // 2).times { io << '\\' } if backslash_count.odd? - str << '"' + io << '"' else quote = !quote end else - backslash_count.times { str << '\\' } + backslash_count.times { io << '\\' } break unless reader.has_next? # `current_char` is neither '\\' nor '"' char = reader.current_char break if char.in?(' ', '\t') && !quote - str << char + io << char end reader.next_char diff --git a/src/regex.cr b/src/regex.cr index c0f0ad56b4da..52b62239559e 100644 --- a/src/regex.cr +++ b/src/regex.cr @@ -399,15 +399,15 @@ class Regex # /#{string}/ # => /\*\?\{\}\./ # ``` def self.escape(str) : String - String.build do |result| + String.build do |io| str.each_byte do |byte| {% begin %} case byte.unsafe_chr when {{*SPECIAL_CHARACTERS}} - result << '\\' - result.write_byte byte + io << '\\' + io.write_byte byte else - result.write_byte byte + io.write_byte byte end {% end %} end diff --git a/src/string.cr b/src/string.cr index 7c9eed3dd186..ef0306b2ee69 100644 --- a/src/string.cr +++ b/src/string.cr @@ -180,8 +180,8 @@ class String # String.new(slice, "GB2312") # => "好" # ``` def self.new(bytes : Bytes, encoding : String, invalid : Symbol? = nil) : String - String.build do |str| - String.encode(bytes, encoding, "UTF-8", str, invalid) + String.build do |io| + String.encode(bytes, encoding, "UTF-8", io, invalid) end end @@ -285,9 +285,9 @@ class String # resizes as needed. # # ``` - # str = String.build do |str| - # str << "hello " - # str << 1 + # str = String.build do |io| + # io << "hello " + # io << 1 # end # str # => "hello 1" # ``` @@ -4598,9 +4598,9 @@ class String chars.insert(last_alnum, carry) end - String.build(chars.size) do |str| + String.build(chars.size) do |io| chars.each do |char| - str << char + io << char end end end diff --git a/src/time/format.cr b/src/time/format.cr index 6f09a1c90229..3e2c23f0d90e 100644 --- a/src/time/format.cr +++ b/src/time/format.cr @@ -88,8 +88,8 @@ struct Time::Format # Turns a `Time` into a `String`. def format(time : Time) : String - String.build do |str| - format time, str + String.build do |io| + format time, io end end diff --git a/src/uri.cr b/src/uri.cr index dfdf26f9f419..033226459dfb 100644 --- a/src/uri.cr +++ b/src/uri.cr @@ -230,15 +230,15 @@ class URI string_size += query.bytesize + 1 end - String.build(string_size) do |str| + String.build(string_size) do |io| if @path.empty? - str << "/" unless opaque? + io << "/" unless opaque? else - str << @path + io << @path end if (query = @query) && !query.empty? - str << '?' << query + io << '?' << query end end end diff --git a/src/uuid.cr b/src/uuid.cr index 7c8d44478f84..e908abf9895e 100644 --- a/src/uuid.cr +++ b/src/uuid.cr @@ -284,9 +284,9 @@ struct UUID # uuid2.urn # => "urn:uuid:c49fc136-9362-4414-81a5-9a7e0fcca0f1" # ``` def urn : String - String.build(45) do |str| - str << "urn:uuid:" - to_s(str) + String.build(45) do |io| + io << "urn:uuid:" + to_s(io) end end diff --git a/src/xml/builder.cr b/src/xml/builder.cr index 1ebe23efcd47..3f5933644eff 100644 --- a/src/xml/builder.cr +++ b/src/xml/builder.cr @@ -323,8 +323,8 @@ module XML # string # => "\n\n Jane\n Doe\n\n" # ``` def self.build(version : String? = nil, encoding : String? = nil, indent = nil, quote_char = nil, &) - String.build do |str| - build(str, version, encoding, indent, quote_char) do |xml| + String.build do |io| + build(io, version, encoding, indent, quote_char) do |xml| yield xml end end @@ -347,8 +347,8 @@ module XML # string # => "\n Jane\n Doe\n\n" # ``` def self.build_fragment(*, indent = nil, quote_char = nil, &) - String.build do |str| - build_fragment(str, indent: indent, quote_char: quote_char) do |xml| + String.build do |io| + build_fragment(io, indent: indent, quote_char: quote_char) do |xml| yield xml end end diff --git a/src/xml/node.cr b/src/xml/node.cr index 45878e762b0f..24b614165867 100644 --- a/src/xml/node.cr +++ b/src/xml/node.cr @@ -426,8 +426,8 @@ class XML::Node # # See `XML::SaveOptions.xml_default` for default options. def to_xml(indent : Int = 2, indent_text = " ", options : SaveOptions = SaveOptions.xml_default) : String - String.build do |str| - to_xml str, indent, indent_text, options + String.build do |io| + to_xml io, indent, indent_text, options end end diff --git a/src/yaml/builder.cr b/src/yaml/builder.cr index 2764580dde13..12b9878ba660 100644 --- a/src/yaml/builder.cr +++ b/src/yaml/builder.cr @@ -240,8 +240,8 @@ module YAML # string # => "---\nfoo:\n- 1\n- 2\n" # ``` def self.build(&) - String.build do |str| - build(str) do |yaml| + String.build do |io| + build(io) do |yaml| yield yaml end end