--[[----------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2019 Adobe
All Rights Reserved.

NOTICE: All information contained herein is, and remains
the property of Adobe and its suppliers, if any. The intellectual
and technical concepts contained herein are proprietary to Adobe
and its suppliers and are protected by all applicable intellectual
property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material
is strictly forbidden unless prior written permission is obtained
from Adobe.

----------------------------------------------------------------------------]]--

local string_find = assert( string.find )
local string_replace = assert( string.replace )

--------------------------------------------------------------------------------
--	From: https://wiki.corp.adobe.com/display/Globalization/zString+1.5+escape+sequence

local kHashSequences = {

 	[ "#{tab}"    ] = "^U+0009",			-- horizontal tabulation
	[ "#{cr}"     ] = "^U+000D",			-- carriage return
	[ "#{lf}"     ] = "^U+000A",			-- line feed
	[ "#{nbsp}"   ] = "^U+00A0",			-- non-breaking space
	[ "#{iexcl}"  ] = "^U+00A1",			-- inverted exclamation mark
	[ "#{cent}"   ] = "^U+00A2",			-- cent sign
	[ "#{pound}"  ] = "^U+00A3",			-- pound sign
	[ "#{curren}" ] = "^U+00A4",			-- currency sign
	[ "#{yen}"    ] = "^U+00A5",			-- yuan sign
	[ "#{brvbar}" ] = "^U+00A6",			-- broken vertical bar
	[ "#{sect}"   ] = "^U+00A7",			-- section sign
	[ "#{uml}"    ] = "^U+00A8",			-- spacing diaeresis
	[ "#{copy}"   ] = "^U+00A9",			-- copyright sign
	[ "#{ordf}"   ] = "^U+00AA",			-- feminine ordinal indicator
	[ "#{laquo}"  ] = "^U+00AB",			-- left-pointing double angle quotation mark
	[ "#{not}"    ] = "^U+00AC",			-- not sign
	[ "#{shy}"    ] = "^U+00AD",			-- discretionary hyphen
	[ "#{reg}"    ] = "^U+00AE",			-- registered trade mark sign
	[ "#{macr}"   ] = "^U+00AF",			-- spacing macron (overline)
	[ "#{deg}"    ] = "^U+00B0",			-- degree sign
	[ "#{plusmn}" ] = "^U+00B1",			-- plus-or-minus sign
	[ "#{sup2}"   ] = "^U+00B2",			-- superscript digit two
	[ "#{sup3}"   ] = "^U+00B3",			-- superscript digit three
	[ "#{acute}"  ] = "^U+00B4",			-- acute accent
	[ "#{micro}"  ] = "^U+00B5",			-- micro sign
	[ "#{para}"   ] = "^U+00B6",			-- paragraph sign
	[ "#{middot}" ] = "^U+00B7",			-- middle dot
	[ "#{cedil}"  ] = "^U+00B8",			-- spacing cedilla
	[ "#{sup1}"   ] = "^U+00B9",			-- superscript digit one
	[ "#{ordm}"   ] = "^U+00BA",			-- masculine ordinal indicator
	[ "#{raquo}"  ] = "^U+00BB",			-- right-pointing double angle quotation mark
	[ "#{frac14}" ] = "^U+00BC",			-- fraction one quarter
	[ "#{frac12}" ] = "^U+00BD",			-- fraction one half
	[ "#{frac34}" ] = "^U+00BE",			-- fraction three quarters
	[ "#{iquest}" ] = "^U+00BF",			-- inverted question mark
	[ "#{Agrave}" ] = "^U+00C0",			-- latin capital letter A grave
	[ "#{Aacute}" ] = "^U+00C1",			-- latin capital letter A with acute
	[ "#{Acirc}"  ] = "^U+00C2",			-- latin capital letter A with circumflex
	[ "#{Atilde}" ] = "^U+00C3",			-- latin capital letter A with tilde
	[ "#{Auml}"   ] = "^U+00C4",			-- latin capital letter A with diaeresis
	[ "#{Aring}"  ] = "^U+00C5",			-- latin capital letter A with ring above = latin capital letter A ring
	[ "#{AElig}"  ] = "^U+00C6",			-- latin capital letter AE = latin capital ligature AE
	[ "#{Ccedil}" ] = "^U+00C7",			-- latin capital letter C with cedilla
	[ "#{Egrave}" ] = "^U+00C8",			-- latin capital letter E with grave
	[ "#{Eacute}" ] = "^U+00C9",			-- latin capital letter E with acute
	[ "#{Ecirc}"  ] = "^U+00CA",			-- latin capital letter E with circumflex
	[ "#{Euml}"   ] = "^U+00CB",			-- latin capital letter E with diaeresis
	[ "#{Igrave}" ] = "^U+00CC",			-- latin capital letter I with grave
	[ "#{Iacute}" ] = "^U+00CD",			-- latin capital letter I with acute
	[ "#{Icirc}"  ] = "^U+00CE",			-- latin capital letter I with circumflex
	[ "#{Iuml}"   ] = "^U+00CF",			-- latin capital letter I with diaeresis
	[ "#{ETH}"    ] = "^U+00D0",			-- latin capital letter ETH
	[ "#{Ntilde}" ] = "^U+00D1",			-- latin capital letter N with tilde
	[ "#{Ograve}" ] = "^U+00D2",			-- latin capital letter O with grave
	[ "#{Oacute}" ] = "^U+00D3",			-- latin capital letter O with acute
	[ "#{Ocirc}"  ] = "^U+00D4",			-- latin capital letter O with circumflex
	[ "#{Otilde}" ] = "^U+00D5",			-- latin capital letter O with tilde
	[ "#{Ouml}"   ] = "^U+00D6",			-- latin capital letter O with diaeresis
	[ "#{times}"  ] = "^U+00D7",			-- multiplication sign
	[ "#{Oslash}" ] = "^U+00D8",			-- latin capital letter O with stroke = latin capital letter O slash
	[ "#{Ugrave}" ] = "^U+00D9",			-- latin capital letter U with grave
	[ "#{Uacute}" ] = "^U+00DA",			-- latin capital letter U with acute
	[ "#{Ucirc}"  ] = "^U+00DB",			-- latin capital letter U with circumflex
	[ "#{Uuml}"   ] = "^U+00DC",			-- latin capital letter U with diaeresis
	[ "#{Yacute}" ] = "^U+00DD",			-- latin capital letter Y with acute
	[ "#{THORN}"  ] = "^U+00DE",			-- latin capital letter THORN
	[ "#{szlig}"  ] = "^U+00DF",			-- latin small letter sharp s = ess-zed
	[ "#{agrave}" ] = "^U+00E0",			-- latin small letter a with grave = latin small letter a grave
	[ "#{aacute}" ] = "^U+00E1",			-- latin small letter a with acute
	[ "#{acirc}"  ] = "^U+00E2",			-- latin small letter a with circumflex
	[ "#{atilde}" ] = "^U+00E3",			-- latin small letter a with tilde
	[ "#{auml}"   ] = "^U+00E4",			-- latin small letter a with diaeresis
	[ "#{aring}"  ] = "^U+00E5",			-- latin small letter a with ring above = latin small letter a ring
	[ "#{aelig}"  ] = "^U+00E6",			-- latin small letter ae = latin small ligature ae
	[ "#{ccedil}" ] = "^U+00E7",			-- latin small letter c with cedilla
	[ "#{egrave}" ] = "^U+00E8",			-- latin small letter e with grave
	[ "#{eacute}" ] = "^U+00E9",			-- latin small letter e with acute
	[ "#{ecirc}"  ] = "^U+00EA",			-- latin small letter e with circumflex
	[ "#{euml}"   ] = "^U+00EB",			-- latin small letter e with diaeresis
	[ "#{igrave}" ] = "^U+00EC",			-- latin small letter i with grave
	[ "#{iacute}" ] = "^U+00ED",			-- latin small letter i with acute
	[ "#{icirc}"  ] = "^U+00EE",			-- latin small letter i with circumflex
	[ "#{iuml}"   ] = "^U+00EF",			-- latin small letter i with diaeresis
	[ "#{eth}"    ] = "^U+00F0",			-- latin small letter eth
	[ "#{ntilde}" ] = "^U+00F1",			-- latin small letter n with tilde
	[ "#{ograve}" ] = "^U+00F2",			-- latin small letter o with grave
	[ "#{oacute}" ] = "^U+00F3",			-- latin small letter o with acute
	[ "#{ocirc}"  ] = "^U+00F4",			-- latin small letter o with circumflex
	[ "#{otilde}" ] = "^U+00F5",			-- latin small letter o with tilde
	[ "#{ouml}"   ] = "^U+00F6",			-- latin small letter o with diaeresis
	[ "#{divide}" ] = "^U+00F7",			-- division sign
	[ "#{oslash}" ] = "^U+00F8",			-- latin small letter o slash
	[ "#{ugrave}" ] = "^U+00F9",			-- latin small letter u with grave
	[ "#{uacute}" ] = "^U+00FA",			-- latin small letter u with acute
	[ "#{ucirc}"  ] = "^U+00FB",			-- latin small letter u with circumflex
	[ "#{uuml}"   ] = "^U+00FC",			-- latin small letter u with diaeresis
	[ "#{yacute}" ] = "^U+00FD",			-- latin small letter y with acute
	[ "#{thorn}"  ] = "^U+00FE",			-- latin small letter thorn
	[ "#{yuml}"   ] = "^U+00FF",			-- latin small letter y with diaeresis
	[ "#{quot}"   ] = "^U+0022",			-- quotation mark = APL quote
	[ "#{amp}"    ] = "^U+0026",			-- ampersand
	[ "#{lt}"     ] = "^U+003C",			-- less-than sign
	[ "#{gt}"     ] = "^U+003E",			-- greater-than sign
	[ "#{OElig}"  ] = "^U+0152",			-- latin capital ligature OE
	[ "#{oelig}"  ] = "^U+0153",			-- latin small ligature oe
	[ "#{Scaron}" ] = "^U+0160",			-- latin capital letter S with caron
	[ "#{scaron}" ] = "^U+0161",			-- latin small letter s with caron
	[ "#{Yuml}"   ] = "^U+0178",			-- latin capital letter Y with diaeresis
	[ "#{circ}"   ] = "^U+02C6",			-- modifier letter circumflex accent
	[ "#{tilde}"  ] = "^U+02DC",			-- small tilde
	[ "#{ensp}"   ] = "^U+2002",			-- en space
	[ "#{emsp}"   ] = "^U+2003",			-- em space
	[ "#{thinsp}" ] = "^U+2009",			-- thin space
	[ "#{zwnj}"   ] = "^U+200C",			-- zero width non-joiner
	[ "#{zwj}"    ] = "^U+200D",			-- zero width joiner
	[ "#{lrm}"    ] = "^U+200E",			-- left-to-right mark
	[ "#{rlm}"    ] = "^U+200F",			-- right-to-left mark
	[ "#{ndash}"  ] = "^U+2013",			-- en dash
	[ "#{mdash}"  ] = "^U+2014",			-- em dash
	[ "#{lsquo}"  ] = "^U+2018",			-- left single quotation mark
	[ "#{rsquo}"  ] = "^U+2019",			-- right single quotation mark
	[ "#{sbquo}"  ] = "^U+201A",			-- single low-9 quotation mark
	[ "#{ldquo}"  ] = "^U+201C",			-- left double quotation mark
	[ "#{rdquo}"  ] = "^U+201D",			-- right double quotation mark
	[ "#{bdquo}"  ] = "^U+201E",			-- double low-9 quotation mark
	[ "#{dagger}" ] = "^U+2020",			-- dagger
	[ "#{Dagger}" ] = "^U+2021",			-- double dagger
	[ "#{permil}" ] = "^U+2030",			-- per mille sign
	[ "#{lsaquo}" ] = "^U+2039",			-- single left-pointing angle quotation mark
	[ "#{rsaquo}" ] = "^U+203A",			-- single right-pointing angle quotation mark
	[ "#{euro}"   ] = "^U+20AC",			-- euro sign
}

--------------------------------------------------------------------------------

local function stringWithReplacedHashSequences( str )

	-- Short-circuit if no hash sequences in this string.

	local hashStart = string_find( str, '#{[^}]+}' )

	if not hashStart then
		return str
	end

	for k, v in pairs( kHashSequences ) do
		str = string_replace( str, k, v )
	end

	return str
	
end


--------------------------------------------------------------------------------

return {

	stringWithReplacedHashSequences = stringWithReplacedHashSequences,
}




