json_escape Function

private pure function json_escape(s) result(out)

Minimal JSON string escaping: backslash, double-quote, and the common control characters. Doc/name/units strings in this codebase are plain single-line ASCII, so this is deliberately not a general-purpose escaper.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: s

Return Value character(len=:), allocatable


Called by

proc~~json_escape~~CalledByGraph proc~json_escape json_escape proc~json_string_array json_string_array proc~json_string_array->proc~json_escape proc~schema_render_json nml_schema_t%schema_render_json proc~schema_render_json->proc~json_escape proc~write_key_json write_key_json proc~schema_render_json->proc~write_key_json proc~write_key_json->proc~json_escape proc~write_key_json->proc~json_string_array

Variables

Type Visibility Attributes Name Initial
character(len=1), private :: c
integer, private :: i

Source Code

   pure function json_escape(s) result(out)
      !! Minimal JSON string escaping: backslash, double-quote, and the
      !! common control characters.  Doc/name/units strings in this
      !! codebase are plain single-line ASCII, so this is deliberately
      !! not a general-purpose escaper.
      character(len=*), intent(in) :: s
      character(len=:), allocatable :: out
      integer :: i
      character :: c
      out = ""
      do i = 1, len(s)
         c = s(i:i)
         select case (c)
         case ('"')
            out = out//'\"'
         case ("\")
            out = out//"\\"
         case (achar(10))
            out = out//"\n"
         case (achar(9))
            out = out//"\t"
         case default
            if (iachar(c) >= 32) out = out//c
         end select
      end do
   end function json_escape