Processing strings

Version :
12.06.2024, 12:35 Uhr

Processing strings

static int replace_all(
  char* str,
  char* search,
  char* replace)

Replace all occurences of a string with another string. The function also operates where the replacement string is a part of mulitple of the searched string. The searched sting may not be empty.

Name Type Default Description
str char* - A replace will be made in this string
search char* - Search for this string. The search string may not be empty.
replace char* - Replace with this string. This string may be empty.


priint:comet InDesign® Plug-Ins, comet_pdf

static int ireplace_all(
  char* str,
  char* key,
  int value)

Replace all occurences of a string with a number. This command is frequently used to update placeholder definitions in tagged text from the database and to replace the text placeholders <ID>, <ID2>, ... there with their current values. The search string may not be empty.

Name Type Default Description
str char* - A replace will be made in this string
search char* - Search for this string. The search string may not be empty.
value int - Replace with this number.


priint:comet InDesign® Plug-Ins, comet_pdf

static int unix_to_win(char* str)

Replace all unix line separators with Windows line separators. Windows line separators consist of two characters, Unix line separators have only one (which is indeed enough). The string then will be made longer by the replacement. You should bear this in mind and reserve sufficient memory.

Name Type Default Description
str char* - String to be processed.


priint:comet InDesign® Plug-Ins, comet_pdf

static int xpress_to_tagged(char* tt)

Convert XPress marked text into tagged text. The tagged text is not completely InDesign® compatible. It contains further tags for the definition of placeholders in texts and for frames.

Name Type Default Description
str char* - String to be processed.


priint:comet InDesign® Plug-Ins, comet_pdf

static char* replace_typografics(char* str)

Replace typografic quotas.When inserting text into InDesign® documents, quotas can be automatically replaced with typographic quotas. If you read such texts again from the document (e.g. with textmodel::gettext or table::get_text), they will of course differ from their original. The replace_typographics function replaces these characters with 'nomrmal' quotes.

The following characters are replaced :
Search Replace
"
"
'
'

Name Type Default Description
Return char*   reference to str
str char* - valid string
#include "internal/text.h"
#include "internal/types.h"
int main () { String cstr = string::alloc (); char str[500];
strcpy (str, textmodel::gettext (cstr));
showmessage ("1 : %s", str); text::replace_typografics (str); showmessage ("2 : %s", str);
return 0; }

Typografic quotas can replaced automatically using the keyword kExportPlainNoTypografics.

#include "internal/types.h"
#include "internal/text.h"
int main () { String cstr = string::alloc (); char str[500];
strcpy (str, textmodel::gettext (cstr,   0, kEnd,   kExportPlainNoTypografics));
showmessage ("1 : %s", str);
return 0; }

Get the same result as in example 1 without using replace_typografics. This exampe only works on Mac!

#include "internal/types.h"
int main () { String cstr = string::alloc (); char str[500];
strcpy (str, textmodel::gettext (cstr));
showmessage ("1 : %s", str); if (system::os () == kMacOS) { text::replace_all (str, "\xe2", "'"); text::replace_all (str, "\xd4", "'"); text::replace_all (str, "\xe3", "\""); text::replace_all (str, "\xd2", "\""); } showmessage ("2 : %s", str);
return 0; }

Version 1.3.4 (P/R 100)

priint:comet InDesign® Plug-Ins, comet_pdf

frame::gettext
table::get_text

static char* fortune(
  char* result,
  char* dbname,
  int seed = -1)

Return a fortune cookie

Name Type Default Description
Return char*   result
result char* - allocated result string
dbname char* - name of the db-file or folder containing db files (relative to Comet PlugIn directory or XML path).
seed int -1 random seed


priint:comet InDesign® Plug-Ins, comet_pdf

static char* find_styled_font(
  char* fontfamily,
  char* fontface,
  int italic,
  int weight,
  int stretch,
  int* found = 0)

Find a font face of given properties in a font family. URL[See here for more information about font famiies, font face and the fontDB.]{../InDesign/Plugins/comet_pdf.html#fontstyle}

Name Type Default Description
Return char*   Font face with given properties.

Not every font has font styles for any combination of font size, width, and style. The found font does not necessarily have to fulfill all parameters. But it is the best possible approximation. Siehe hier für weitere Informationen.

The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. See here to learn more about functions returning r/o char* values.

fontfamily char* or String - Name of font family
fontface char* or String - Name of font face. Only used if weight > 900 or stretch > 4.
italic int - Font style

0 : Normal
1 : Italic
weight int - Font weight

100, 200, ..., 900 see here

> 900 : I know the style name and search for the associated Italic / Normal font. fontface must not be empty in this case!
stretch int - Font stretch

-4, -3, ..., 4 : ssee here

> 4 : I know the style name and search for the associated Italic / Normal font. fontface must not be empty in this case!
found int* 0 Return value: Face found or not?

0 : Ignore

v4.1 R23232, 30. Mai 2018. Do not use this function in prior releases!

priint:comet InDesign® Plug-Ins, comet_pdf

fontDB
system::fontdb_count
fontdb_get_fontname
fontdb_by_index
fontdb_by_name
fontdb_mark_missing

static char* translate(
  char* text,
  char* license_key,
  char* dest_lang,
  char* source_lang = 0)

Translate a text. Unlike the translate function (without text::) this function translates free texts into a desired target language independent of the InDesign language.

The AI-based translation service deepl is used for translation. You can find a list of \URL[supported languages here|{../InDesign/Plugins/comet_pdf.html#lang}. The service, like our green power at home, doesn't cost the earth, but you still need a valid and paid license key, which you can purchase here.

The license costs for the deepl service are not included in the costs for the priint:comet plugins.

Please note that TaggedText formatted text is not suitable for translations. In particular, the encoding of Unicode characters in tags of the form <0x00FC> lead to errors here. So you should use unformatted text here if possible. Such as is generated by frame::gettext(gFrame, text, 0, kEnd, kExportPlain); for example.However, and hopefully this won't surprise you, we cannot automatically reapply equivalent formatting to the translated text. For this we would have to know (e.g.) not only that 'police' in Hungarian is 'rendőrség' (well, at least we would have known that), we would also have to know how the word was formatted before and where in the text it is now, etc. .

The deepl integration is based on a REST API provided by deepl and cannot be arbitrarily replaced by any other translation service.

Name Type Default Description
Return char*   Translated text

The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. See here to learn more about functions returning r/o char* values.

text char* oder String - Unformatted input text
license_key char* oder String - Valid deepl license key. These keys have are coming in th following format : xxxxxxxxc-xxxx-xxxx-xxxx-xxxxxxxxxxxx
dest_lang char* oder String - Target language, see here
source_lang char* oder String 0 Source language, see here

deepl is able to detect the source language itself in most cases. And since the translation will of course not work if the source language is wrong, it is generally better not to specify a source language. But for single words like 'was' even deepl can't decide which language is meant. English or German? Then you should specify the source language.
#include "internal/text.h"
#include "internal/types.h"
int main() { String txt = string::alloc();
frame::gettext(gFrame, txt, 0, kEnd, kExportPlain); frame::replace(gFrame, text::translate (txt, "xxxxxxxxc-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "SV", ""), 0, -1, 0);
string::release(txt);
return 0; }

v4.2 R33270, 20. July 2023

priint:comet InDesign® Plug-Ins

translate

Author
Paul Seidel
Version
12.06.2024, 12:35 Uhr
Since
Plugin Version 1.0.10

Alphabetic index HTML hierarchy of classes or Java