check_brackets: Check an RTF file for Balanced Curly Brackets

View source: R/check_brackets.R

check_bracketsR Documentation

Check an RTF file for Balanced Curly Brackets

Description

Checks an RTF file for balanced curly brackets. The RTF file must start with {\rtf1 and ends at the first closing }.

Usage

check_brackets(filename)

Arguments

filename

a length-one character vector indicating the RTF filename to check

Details

An RTF file must begin with {\rtf1 and ends as soon as that opening curly bracket is closed. (Usually anything after the closing curly bracket is ignored by RTF readers.)

Curly brackets appearing in an RTF document need to be escaped with a backslash; this function ignores these.

Value

This function returns a “status code” of zero if the RTF file checks out and has balanced curly brackets. Non-zero status codes indicate a problem. These non-zero status codes are as follows:

Code Meaning
1 Cannot open the file to check curly brackets
2 File did not begin with the required {\rtf1
3 The curly brackets in the file nest too deeply for this program
4 A closing } was found without a prior {
5 The opening {\rtf1 was never closed
6 There is an opening { that was never closed

Author(s)

Stephen Weigand <weigand.stephen@mayo.edu>

Examples


## A valid RTF file
check_brackets(system.file("examples",
                           "hello-world.rtf",
                           package = "rtfSweave"))

## An RTF file missing a closing curly bracket
check_brackets(system.file("examples",
                           "unbalanced.rtf",
                           package = "rtfSweave"))


rtfSweave documentation built on June 21, 2022, 3:01 p.m.