On Jan 28, 2007, at 7:39 PM, karl arder wrote:
Ok, I seem to be hitting my head against every low hanging object...
Song names/paths can have a broader scope of characters than
allowed in a URL. How do I now convert the paths correctly so I
don't get errors with these characters.
I guess I'm plowing over ground that is a well trodden path with
regards to this subject. Are there any other 'surprises' I can look
forward to?
You need to replace the illegal characters with percent codes. For
MacOS, you can use the following function.
Function Escape(theURL as String, charactersToLeaveUnescaped as
String = "", legalURLCharactersToBeEscaped as String = "") As String
if Encoding(theURL) is nil then
// parameter '" + theURL + "' does not have an encoding."
return theURL
end if
soft declare function CFURLCreateStringByAddingPercentEscapes lib
"Carbon.framework" (allocator as Integer, originalString as
CFStringRef, charactersToLeaveUnescaped as CFStringRef,
legalURLCharactersToBeEscaped as CFStringRef, encoding as UInt32) as
CFStringRef
const kCFAllocatorDefault = 0
return CFURLCreateStringByAddingPercentEscapes
(kCFAllocatorDefault, theURL, charactersToLeaveUnescaped,
legalURLCharactersToBeEscaped, Encoding(theURL).Code)
End Function
And here is its inverse.
Function Unescape(theURL as String, charactersToLeaveEscaped as
String = "") As String
if Encoding(theURL) is nil then
// parameter '" + theURL + "' does not have an encoding."
return theURL
end if
theURL = ConvertEncoding(theURL, Encodings.UTF8)
soft declare function CFURLCreateStringByReplacingPercentEscapes
lib "Carbon.framework" (allocator as Integer, originalString as
CFStringRef, charactersToLeaveEscaped as CFStringRef) as CFStringRef
const kCFAllocatorDefault = 0
return CFURLCreateStringByReplacingPercentEscapes
(kCFAllocatorDefault, theURL, charactersToLeaveEscaped)
End Function
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>