Skip to content

Commit

Permalink
Rename String.build block parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Aug 2, 2023
1 parent 0efe3c1 commit bf14850
Show file tree
Hide file tree
Showing 41 changed files with 254 additions and 254 deletions.
8 changes: 4 additions & 4 deletions spec/std/base64_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -169,27 +169,27 @@ 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
end

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
Expand Down
8 changes: 4 additions & 4 deletions spec/std/io/buffered_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/std/io/io_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions spec/std/string_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/std/yaml/serialization_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/std/yaml/yaml_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 21 additions & 21 deletions src/compiler/crystal/codegen/ast.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/crystal/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/crystal/macros/interpreter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
44 changes: 22 additions & 22 deletions src/compiler/crystal/semantic/call_error.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/crystal/semantic/cleanup_transformer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/crystal/semantic/default_arguments.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions src/compiler/crystal/semantic/exception.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit bf14850

Please sign in to comment.