File: uriencode.cmake

package info (click to toggle)
kdoctools 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,924 kB
  • sloc: xml: 5,732; cpp: 901; makefile: 3; sh: 1
file content (23 lines) | stat: -rw-r--r-- 1,039 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Encode an URI according to RFC 2396
# kdoctools_encode_uri takes a variable name and it encodes
# its value according to RFC 2396 (minus few reserved characters)
# overwriting the original value.
#
# SPDX-FileCopyrightText: 2014 Luigi Toscano <luigi.toscano@tiscali.it>
#
# SPDX-License-Identifier: BSD-3-Clause

function(kdoctools_encode_uri _original_uri)
    find_package(Perl REQUIRED)
    find_package(PerlModules COMPONENTS URI::Escape REQUIRED)
    # properly encode the URI
    string(REPLACE "\"" "\\\"" escaped_uri "${${_original_uri}}")
    execute_process(COMMAND ${PERL_EXECUTABLE} -MURI::Escape -e "print uri_escape_utf8(\"${escaped_uri}\", \"^A-Za-z0-9\\-\\._~\\/:\");"
                    OUTPUT_VARIABLE encoded_uri
                    RESULT_VARIABLE res_encoding
                    OUTPUT_STRIP_TRAILING_WHITESPACE)
    if (NOT ${res_encoding} EQUAL 0)
        message(FATAL_ERROR "Problem while encoding the URI ${${_original_uri}}")
    endif()
    set(${_original_uri} "${encoded_uri}" PARENT_SCOPE)
endfunction()