f_subptr_str ============ Return a borrowed rank-one ``character(len=1)`` view of a persistent string or contiguous character array, with every count and offset in **characters**. .. code-block:: fortran use futile ! or: use f_subptr_module, only: f_subptr_str Signature --------- Generated from the FYPP documentation stub ``doc/generated/f_subptr_doc.f90`` (emitted by ``fypp/subptr-doc.fypp`` from the same loops as ``flib/f_subptr.f90``). .. f:autointerface:: f_subptr_str Typical calls ------------- .. code-block:: fortran characters => f_subptr_str(text) characters => f_subptr_str(strings, from=offset, n=count) The window controls have the defaults and exclusivity rules of :doc:`f_subptr`, but count characters, not string elements. There is no ``ptr_addr`` spelling: the capacity of a character source is always known from its length and array size, including for scalar strings. Returns ------- A ``character(len=1)`` pointer with one element per storage character, in Fortran array-element order. For ``character(len=3) :: strings(2)``, ``f_subptr(strings)`` preserves two length-three elements, while ``f_subptr_str(strings)`` exposes six length-one elements. Trailing blanks and embedded NULs are included; no separators or terminators are inserted. Supported ranks --------------- .. fortran-specifics:: f_subptr_str :args: ptr Notes ----- .. rubric:: Ownership Writes through the view modify the original string storage. The view neither allocates nor owns payload: keep the owner alive and nullify the view before freeing the owner. .. rubric:: Empty windows An explicit zero character window returns null. An implicit zero-character payload (a zero-length scalar, or an array of zero-length strings) returns an associated empty view backed by a module-owned zero-element target; no owner-address identity is promised in that case. As for :doc:`f_subptr`, never bounds-remap a null result. .. rubric:: Errors Windows exceeding the known capacity, invalid selectors, overflow and noncontiguous nonempty storage raise ``ERR_INVALID_MALLOC``; a caught error returns null. .. rubric:: C interoperability Where default character kind equals ``c_char``, a nonempty view's ``c_loc`` can be passed to C. The API does not append NUL, trim blanks, encode text or scan for a terminator; units are storage characters, not Unicode code points. Supply a NUL inside the selected window before calling an unbounded C routine such as ``strlen``. An empty view supplies no C string address. Examples -------- Compiled and run by CI (``tests/flib/character_buffers_check.F90``): shared addresses, C ``strlen`` and C-side mutation through the view. .. fortranliteral:: tests/flib/character_buffers_check.F90 :marker: character_views See also -------- * :doc:`f_subptr` -- the same windows counted in elements, for any intrinsic type. * :doc:`f_memcpy` -- copy raw storage into or out of a character view. * :doc:`f_dump_buffer` -- binding-owned character storage, copied rather than borrowed. * ``f_atoi`` / ``f_itoa`` -- explicit ASCII conversions instead of raw copies (:doc:`/memory`).