-module(system_text).
-compile(nowarn_unused_vars).
-compile(nowarn_unused_function).
-export([string_builder_ctor_z18115_a39/2, string_builder_ctor_z524259_a4/1, string_builder_ctor_z721_c83_c5/1, string_builder_ctor/0, string_builder_append_z721_c83_c5/2, string_builder_append_244_c7_c_d6/2, string_builder_append_61_b1_c_a/3, string_builder_append_z524259_a4/2, string_builder_append_5_e38073_b/2, string_builder_append_z1_f_b_c_c_d16/2, string_builder_append_4_e60_e31_b/2, string_builder_append_z372_e4_d23/2, string_builder_append_43_a65_c09/2, string_builder_append_format_433_e080/3, string_builder_append_format_z3_b30_e_c65/4, string_builder_append_line/1, string_builder_append_line_z721_c83_c5/2, string_builder_clear/1, string_builder_get_length/1, string_builder_replace_z766_f94_c0/3, string_builder_replace_z384_f8060/3, string_builder_get_chars_z524259_a4/2, string_builder_to_string_z37302880/3]).

string_builder_ctor_z18115_a39(Value, Capacity) ->
    Ref = erlang:make_ref(),
    erlang:put(Ref, #{field_buf => fable_utils:new_ref([])}),
    erlang:put(Ref, maps:merge(erlang:get(Ref), #{to_string => fun() ->
        fable_string:concat(maps:get(field_buf, erlang:get(Ref)))
end})),
    case not fable_string:is_null_or_empty(Value) of
        true ->
            put(maps:get(field_buf, erlang:get(Ref)), get(maps:get(field_buf, erlang:get(Ref))) ++ [Value])
        ;
        false ->
            ok
    end,
    Ref
.

string_builder_ctor_z524259_a4(Capacity) ->
    string_builder_ctor_z18115_a39(<<""/utf8>>, Capacity)
.

string_builder_ctor_z721_c83_c5(Value) ->
    string_builder_ctor_z18115_a39(Value, 16)
.

string_builder_ctor() ->
    string_builder_ctor_z18115_a39(<<""/utf8>>, 16)
.

string_builder_append_z721_c83_c5(X, S) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [S]),
    X
.

string_builder_append_244_c7_c_d6(X, C) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [<<(C)/utf8>>]),
    X
.

string_builder_append_61_b1_c_a(X, C, RepeatCount) ->
    S = fable_string:replicate(RepeatCount, <<(C)/utf8>>),
    begin put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [S]),
    X end
.

string_builder_append_z524259_a4(X, O) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [integer_to_binary(O)]),
    X
.

string_builder_append_5_e38073_b(X, O) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [fable_convert:to_string(O)]),
    X
.

string_builder_append_z1_f_b_c_c_d16(X, O) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [atom_to_binary(O)]),
    X
.

string_builder_append_4_e60_e31_b(X, O) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [fable_convert:to_string(O)]),
    X
.

string_builder_append_z372_e4_d23(X, Cs) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [fable_string:string_ctor_chars(erlang:get(Cs))]),
    X
.

string_builder_append_43_a65_c09(X, S) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [iolist_to_binary(get(maps:get(field_buf, get(S))))]),
    X
.

string_builder_append_format_433_e080(X, Fmt, O) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [fable_string:format(Fmt, [O | []])]),
    X
.

string_builder_append_format_z3_b30_e_c65(X, Fmt, O1, O2) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [fable_string:format(Fmt, [O1 | [O2 | []]])]),
    X
.

string_builder_append_line(X) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [<<"\n"/utf8>>]),
    X
.

string_builder_append_line_z721_c83_c5(X, S) ->
    put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [S]),
    begin put(maps:get(field_buf, erlang:get(X)), get(maps:get(field_buf, erlang:get(X))) ++ [<<"\n"/utf8>>]),
    X end
.

string_builder_clear(X) ->
    put(maps:get(field_buf, erlang:get(X)), []),
    X
.

string_builder_get_length(X) ->
    Len_ref = fable_utils:new_ref(0),
    Len_ref_result = begin begin For_loop_0 = fun For_loop_0(I) ->
        case I >= 0 of
            true ->
                erlang:put(Len_ref, erlang:get(Len_ref) + (byte_size(lists:nth(I + 1, get(maps:get(field_buf, erlang:get(X))))))),
                For_loop_0(I - 1)
            ;
            false ->
                ok
        end
end,
    For_loop_0((erlang:length(erlang:get(maps:get(field_buf, erlang:get(X))))) - 1) end,
    erlang:get(Len_ref) end,
    erlang:erase(Len_ref),
    Len_ref_result
.

string_builder_replace_z766_f94_c0(X, OldValue, NewValue) ->
    begin For_loop_1 = fun For_loop_1(I) ->
        case I >= 0 of
            true ->
                put(maps:get(field_buf, erlang:get(X)), fable_resize_array:set_item(get(maps:get(field_buf, erlang:get(X))), I, fable_string:replace(lists:nth(I + 1, get(maps:get(field_buf, erlang:get(X)))), OldValue, NewValue))),
                For_loop_1(I - 1)
            ;
            false ->
                ok
        end
end,
    For_loop_1((erlang:length(erlang:get(maps:get(field_buf, erlang:get(X))))) - 1) end,
    X
.

string_builder_replace_z384_f8060(X, OldValue, NewValue) ->
    Str = fable_string:replace(iolist_to_binary(get(maps:get(field_buf, get(X)))), OldValue, NewValue),
    string_builder_append_z721_c83_c5(string_builder_clear(X), Str)
.

string_builder_get_chars_z524259_a4(X, Index) ->
    Str = iolist_to_binary(get(maps:get(field_buf, get(X)))),
    binary:at(Str, Index)
.

string_builder_to_string_z37302880(X, FirstIndex, Length) ->
    fable_string:substring(iolist_to_binary(get(maps:get(field_buf, get(X)))), FirstIndex, Length)
.
