Skip to main content

##quote

Takes a single argument and returns that argument quoted.

Description

This macro preprocessor function takes a single argument and returns that argument quoted. If the argument already contains quote characters it escapes these quote characters by doubling them. It has the form:

##quote(value)

where value is a literal that is converted to a quoted string. In value a parenthesis character or a quote character must be paired. For example, the following is a valid value:

#define qtest ##quote(He said "Yes" after much debate)
   ZZWRITE $$$qtest

it returns "He said ""Yes"" after much debate". ##quote(This (") is a quote character) is not a valid value.

Parentheses within a value string must be paired. The following is a valid value:

#define qtest2 ##quote(After (a lot of) debate)
   ZZWRITE $$$qtest2

The ##beginquote .... ##EndQuote directives allow for an unpaired parenthesis character or a quote character.

The following example shows the use of ##quote:

#define AssertEquals(%e1,%e2) DO AssertEquals(%e1,%e2,##quote(%e1)_" == "_##quote(%e2))
Main ;
  SET a="abstract"
  WRITE "Test 1:",!
  $$$AssertEquals(a,"abstract")
  WRITE "Test 2:",!
  $$$AssertEquals(a_"","abstract")
  WRITE "Test 3:",!
  $$$AssertEquals("abstract","abstract")
  WRITE "All done"
  QUIT
AssertEquals(e1,e2,desc) ;
  WRITE desc_" is "_$SELECT(e1=e2:"true",1:"false"),!
  QUIT

##quote Nesting

InterSystems IRIS supports nesting within a ##quote function. ##quote can nest the following macro functions: ##BeginLit...##EndLit, ##function, ##lit, ##quote, ##expression, ##SafeExpression, ##stripq, ##unique, and ##this.

FeedbackOpens in a new tab