escape_string Subroutine

private subroutine escape_string(str_in, str_out)

Arguments

Type IntentOptional AttributesName
character(kind=CK,len=*), intent(in) :: str_in
character(kind=CK,len=:), intent(out), allocatable:: str_out

Description

Add the escape characters to a string for adding to JSON.

Called By

proc~~escape_string~~CalledByGraph proc~escape_string escape_string proc~json_value_add_string json_value_add_string proc~json_value_add_string->proc~escape_string interface~json_add json_add proc~json_value_add_string->interface~json_add proc~wrap_json_value_add_string wrap_json_value_add_string proc~wrap_json_value_add_string->proc~json_value_add_string proc~json_value_add_string_name_ascii json_value_add_string_name_ascii proc~json_value_add_string_name_ascii->proc~json_value_add_string proc~json_value_add_string_val_ascii json_value_add_string_val_ascii proc~json_value_add_string_val_ascii->proc~json_value_add_string interface~json_add->proc~json_value_add_string proc~json_value_add_logical json_value_add_logical interface~json_add->proc~json_value_add_logical proc~json_value_add_double json_value_add_double interface~json_add->proc~json_value_add_double proc~json_value_add_logical_vec json_value_add_logical_vec interface~json_add->proc~json_value_add_logical_vec proc~json_value_add_integer json_value_add_integer interface~json_add->proc~json_value_add_integer proc~json_value_add_double_vec json_value_add_double_vec interface~json_add->proc~json_value_add_double_vec proc~json_value_add_integer_vec json_value_add_integer_vec interface~json_add->proc~json_value_add_integer_vec proc~json_value_add_string_vec json_value_add_string_vec interface~json_add->proc~json_value_add_string_vec proc~json_value_add_logical->interface~json_add proc~json_update_integer json_update_integer proc~json_update_integer->interface~json_add proc~test_7 test_7 proc~test_7->interface~json_add proc~json_value_add_double->interface~json_add proc~parse_array parse_array proc~parse_array->interface~json_add proc~parse_value parse_value proc~parse_array->proc~parse_value proc~json_value_add_logical_vec->interface~json_add proc~test_12 test_12 proc~test_12->interface~json_add interface~json_update json_update proc~test_12->interface~json_update proc~add_variables_to_input add_variables_to_input proc~add_variables_to_input->interface~json_add proc~parse_object parse_object proc~parse_object->interface~json_add proc~parse_object->proc~parse_object proc~parse_object->proc~parse_value proc~json_value_add_integer->interface~json_add proc~json_update_double json_update_double proc~json_update_double->interface~json_add proc~json_value_add_double_vec->interface~json_add proc~json_update_logical json_update_logical proc~json_update_logical->interface~json_add proc~test_2 test_2 proc~test_2->interface~json_add proc~test_2->proc~add_variables_to_input proc~test_2->interface~json_update proc~json_value_add_integer_vec->interface~json_add proc~json_update_string json_update_string proc~json_update_string->interface~json_add proc~json_value_add_string_vec->interface~json_add proc~test_4 test_4 proc~test_4->interface~json_add proc~wrap_json_value_add_logical wrap_json_value_add_logical proc~wrap_json_value_add_logical->proc~json_value_add_logical proc~wrap_json_update_integer wrap_json_update_integer proc~wrap_json_update_integer->proc~json_update_integer interface~json_update->proc~json_update_integer interface~json_update->proc~json_update_double interface~json_update->proc~json_update_logical interface~json_update->proc~json_update_string proc~rename rename proc~rename->interface~json_update proc~json_file_update_integer json_file_update_integer proc~json_file_update_integer->interface~json_update proc~json_file_update_string json_file_update_string proc~json_file_update_string->interface~json_update proc~test_1 test_1 proc~test_1->interface~json_update proc~test_10 test_10 proc~test_10->interface~json_update proc~json_file_update_real json_file_update_real proc~json_file_update_real->interface~json_update proc~json_file_update_logical json_file_update_logical proc~json_file_update_logical->interface~json_update proc~wrap_json_file_update_integer wrap_json_file_update_integer proc~wrap_json_file_update_integer->proc~json_file_update_integer proc~json_file_update_string_name_ascii json_file_update_string_name_ascii proc~json_file_update_string_name_ascii->proc~json_file_update_string proc~wrap_json_file_update_string wrap_json_file_update_string proc~wrap_json_file_update_string->proc~json_file_update_string proc~json_file_update_string_val_ascii json_file_update_string_val_ascii proc~json_file_update_string_val_ascii->proc~json_file_update_string program~jf_test_1 jf_test_1 program~jf_test_1->proc~test_1 program~jf_test_10 jf_test_10 program~jf_test_10->proc~test_10 proc~wrap_json_file_update_real wrap_json_file_update_real proc~wrap_json_file_update_real->proc~json_file_update_real proc~wrap_json_file_update_logical wrap_json_file_update_logical proc~wrap_json_file_update_logical->proc~json_file_update_logical program~jf_test_7 jf_test_7 program~jf_test_7->proc~test_7 proc~wrap_json_value_add_double wrap_json_value_add_double proc~wrap_json_value_add_double->proc~json_value_add_double proc~parse_value->proc~parse_array proc~parse_value->proc~parse_object proc~json_parse_string json_parse_string proc~json_parse_string->proc~parse_value proc~json_parse_file json_parse_file proc~json_parse_file->proc~parse_value proc~wrap_json_parse_string wrap_json_parse_string proc~wrap_json_parse_string->proc~json_parse_string interface~json_parse json_parse interface~json_parse->proc~json_parse_string interface~json_parse->proc~json_parse_file proc~test_14 test_14 proc~test_14->interface~json_parse proc~test_8 test_8 proc~test_8->interface~json_parse proc~json_file_load json_file_load proc~json_file_load->interface~json_parse proc~json_file_load_from_string json_file_load_from_string proc~json_file_load_from_string->interface~json_parse program~jf_test_14 jf_test_14 program~jf_test_14->proc~test_14 program~jf_test_8 jf_test_8 program~jf_test_8->proc~test_8 proc~wrap_json_file_load_from_string wrap_json_file_load_from_string proc~wrap_json_file_load_from_string->proc~json_file_load_from_string proc~wrap_json_value_add_logical_vec wrap_json_value_add_logical_vec proc~wrap_json_value_add_logical_vec->proc~json_value_add_logical_vec program~jf_test_12 jf_test_12 program~jf_test_12->proc~test_12 proc~wrap_json_value_add_integer wrap_json_value_add_integer proc~wrap_json_value_add_integer->proc~json_value_add_integer proc~wrap_json_update_double wrap_json_update_double proc~wrap_json_update_double->proc~json_update_double proc~wrap_json_value_add_double_vec wrap_json_value_add_double_vec proc~wrap_json_value_add_double_vec->proc~json_value_add_double_vec proc~wrap_json_update_logical wrap_json_update_logical proc~wrap_json_update_logical->proc~json_update_logical program~jf_test_2 jf_test_2 program~jf_test_2->proc~test_2 proc~wrap_json_value_add_integer_vec wrap_json_value_add_integer_vec proc~wrap_json_value_add_integer_vec->proc~json_value_add_integer_vec proc~json_update_string_name_ascii json_update_string_name_ascii proc~json_update_string_name_ascii->proc~json_update_string proc~wrap_json_update_string wrap_json_update_string proc~wrap_json_update_string->proc~json_update_string proc~json_update_string_val_ascii json_update_string_val_ascii proc~json_update_string_val_ascii->proc~json_update_string proc~json_value_add_string_vec_name_ascii json_value_add_string_vec_name_ascii proc~json_value_add_string_vec_name_ascii->proc~json_value_add_string_vec proc~wrap_json_value_add_string_vec wrap_json_value_add_string_vec proc~wrap_json_value_add_string_vec->proc~json_value_add_string_vec proc~json_value_add_string_vec_val_ascii json_value_add_string_vec_val_ascii proc~json_value_add_string_vec_val_ascii->proc~json_value_add_string_vec program~jf_test_4 jf_test_4 program~jf_test_4->proc~test_4
Help

Variables

TypeVisibility AttributesNameInitial
integer(kind=IK), public :: i
integer(kind=IK), public :: ipos
character(kind=CK,len=1), public :: c
character(kind=CK,len=*), public, parameter:: specials =quotation_mark//backslash//slash//bspace//formfeed//newline//carriage_return//horizontal_tab

Source Code

    subroutine escape_string(str_in, str_out)

    implicit none

    character(kind=CK,len=*),intent(in)              :: str_in
    character(kind=CK,len=:),allocatable,intent(out) :: str_out

    integer(IK) :: i,ipos
    character(kind=CK,len=1) :: c

    character(kind=CK,len=*),parameter :: specials = quotation_mark//&
                                                     backslash//&
                                                     slash//&
                                                     bspace//&
                                                     formfeed//&
                                                     newline//&
                                                     carriage_return//&
                                                     horizontal_tab

    !Do a quick scan for the special characters,
    ! if any are present, then process the string,
    ! otherwise, return the string as is.
    if (scan(str_in,specials)>0) then

        str_out = repeat(space,chunk_size)
        ipos = 1

        !go through the string and look for special characters:
        do i=1,len(str_in)

            c = str_in(i:i)    !get next character in the input string

            !if the string is not big enough, then add another chunk:
            if (ipos+3>len(str_out)) str_out = str_out // repeat(space, chunk_size)

            select case(c)
            case(quotation_mark,backslash,slash)
                str_out(ipos:ipos+1) = backslash//c
                ipos = ipos + 2
            case(bspace)
                str_out(ipos:ipos+1) = '\b'
                ipos = ipos + 2
            case(formfeed)
                str_out(ipos:ipos+1) = '\f'
                ipos = ipos + 2
            case(newline)
                str_out(ipos:ipos+1) = '\n'
                ipos = ipos + 2
            case(carriage_return)
                str_out(ipos:ipos+1) = '\r'
                ipos = ipos + 2
            case(horizontal_tab)
                str_out(ipos:ipos+1) = '\t'
                ipos = ipos + 2
            case default
                str_out(ipos:ipos) = c
                ipos = ipos + 1
            end select

        end do

        !trim the string if necessary:
        if (ipos<len(str_out)+1) then
            if (ipos==1) then
                str_out = ''
            else
                str_out = str_out(1:ipos-1)
            end if
        end if

    else

        str_out = str_in

    end if

    end subroutine escape_string