Curl Global Community
Curl macros introduction (part 4) - Printable Version

+- Curl Global Community (
+-- Forum: Blogs (
+--- Forum: Tech blog (
+---- Forum: Robert blog (
+---- Thread: Curl macros introduction (part 4) (/showthread.php?tid=198)

Curl macros introduction (part 4) - RobertShiplett - 08-10-2011

A Curl macro that accepts expressions: {ndashe }

As you might guess, {ndashe } links Strings from two expressions with a so-called n-dash or Unicode UTF-8 code point 2013 which is the Curl char represented as '\u2013'.

The changes are as follows:

{define-macro public {ndashe ?e1:expression , ?e2:expression}
                                                   || note the comma!

         ?e1 & n-dash & ?e2  || no change here !


and if we now test with

{let public str1:String = "this", str2:String = "these"}
{paragraph We ndashe'd {ndashe {} , {} } }
{expand-to-string {ndashe {} , {}}}

what we will see is
On the web page Curl Wrote:We ndashe'd THIS–THESE
{} & n-dash & {}

One subtle change was required: the "hyphen" could not be used in the macro because it cannot separate two expressions as it is itself used as an infix operator for a {subtract } expression.

Even if it seemed cute to use the hyphen, most often the comma will be your best choice.

But why would we want {ndashi } or {ndashe }? Wouldn't we want an {endash } macro to accept such curl source or text as we pass in?

For that we will need patterns and the Curl {syntax-switch } macro.