Warning, /frameworks/kdelibs4support/cmake/uriencode.cmake is written in an unsupported language. File is not indexed.

0001 # Encode an URI according to RFC 2396
0002 # kdelibs4support_encode_uri takes a variable name and it encodes
0003 # its value according to RFC 2396 (minus few reserved characters)
0004 # overwriting the original value.
0005 #
0006 # Copyright (c) 2014 Luigi Toscano, <luigi.toscano@tiscali.it>
0007 #
0008 # Redistribution and use in source and binary forms, with or without
0009 # modification, are permitted provided that the following conditions
0010 # are met:
0011 # 1. Redistributions of source code must retain the above copyright
0012 #    notice, this list of conditions and the following disclaimer.
0013 # 2. Redistributions in binary form must reproduce the above copyright
0014 #    notice, this list of conditions and the following disclaimer in the
0015 #    documentation and/or other materials provided with the distribution.
0016 # 3. Neither the name of the University nor the names of its contributors
0017 #    may be used to endorse or promote products derived from this software
0018 #    without specific prior written permission.
0019 #
0020 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
0021 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0022 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0023 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0024 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0025 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0026 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0027 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0028 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0029 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0030 # SUCH DAMAGE.
0031 
0032 function(kdelibs4support_encode_uri _original_uri)
0033     find_package(Perl REQUIRED)
0034     find_package(PerlModules COMPONENTS URI::Escape REQUIRED)
0035     # properly encode the URI
0036     string(REPLACE "\"" "\\\"" escaped_uri "${${_original_uri}}")
0037     execute_process(COMMAND perl -MURI::Escape -e "print uri_escape_utf8(\"${escaped_uri}\", \"^A-Za-z0-9\\-\\._~\\/:\");"
0038                     OUTPUT_VARIABLE encoded_uri
0039                     RESULT_VARIABLE res_encoding
0040                     OUTPUT_STRIP_TRAILING_WHITESPACE)
0041     if (NOT ${res_encoding} EQUAL 0)
0042         message(FATAL_ERROR "Problem while encoding the URI ${${_original_uri}}")
0043     endif()
0044     set(${_original_uri} "${encoded_uri}" PARENT_SCOPE)
0045 endfunction()