OpenTTD Source: src/textfile_gui.cpp File Reference

OpenTTD Source 15.3

Enumerations | Functions | Variables
textfile_gui.cpp File Reference

Implementation of textfile window. More...

`#include "stdafx.h"`
`#include "core/backup_type.hpp"`
`#include "fileio_func.h"`
`#include "fontcache.h"`
`#include "gfx_type.h"`
`#include "gfx_func.h"`
`#include "string_func.h"`
`#include "core/string_builder.hpp"`
`#include "textfile_gui.h"`
`#include "dropdown_type.h"`
`#include "dropdown_func.h"`
`#include "gfx_layout.h"`
`#include "debug.h"`
`#include "openttd.h"`
`#include "widgets/misc_widget.h"`
`#include "table/strings.h"`
`#include "table/control_codes.h"`
`#include <zlib.h>`
`#include <lzma.h>`
`#include <regex>`
`#include "safeguards.h"`

Go to the source code of this file.

## Enumerations
enum class | HyperlinkType : uint8_t { Internal , Web , File , Unknown }
| Types of link we support in markdown files. More...

## Functions
static HyperlinkType | ClassifyHyperlink (const std::string &destination, bool trusted)
| Classify the type of hyperlink the destination describes.
static std::string | MakeAnchorSlug (const std::string &line)
| Create a valid slug for the anchor.
bool | CanContinueRealtimeTick ()
static std::vector< char > | Gunzip (std::span< char > input)
| Do an in-memory gunzip operation.
static std::vector< char > | Xunzip (std::span< char > input)
| Do an in-memory xunzip operation.
std::optional< std::string > | GetTextfile (TextfileType type, Subdirectory dir, std::string_view filename)
| Search a textfile file next to the given content.

## Variables
static constexpr std::initializer_list< NWidgetPart > | _nested_textfile_widgets
| Widgets for the textfile window.
static WindowDesc | _textfile_desc (WDP_CENTER, "textfile", 630, 460, WC_TEXTFILE, WC_NONE, {}, _nested_textfile_widgets)
| Window definition for the textfile window.
static const std::regex | _markdown_link_regex {"\\[(.+?)\\]\\‍((.+?)\\‍)", std::regex_constants::ECMAScript | std::regex_constants::optimize}
| Regular expression that searches for Markdown links.

## Detailed Description

Implementation of textfile window.

Definition in file textfile_gui.cpp.

## Enumeration Type Documentation

## ◆ HyperlinkType

enum class HyperlinkType : uint8_t
| strong

Types of link we support in markdown files.

Enumerator
Internal | Internal link, or "anchor" in HTML language.
Web | Link to an external website.
File | Link to a local file.
Unknown | Unknown link.

Definition at line 151 of file textfile_gui.cpp.

## Function Documentation

## ◆ CanContinueRealtimeTick()

bool CanContinueRealtimeTick | ( |  | ) |
| extern

Definition at line 3079 of file window.cpp.

## ◆ ClassifyHyperlink()

static HyperlinkType ClassifyHyperlink | ( | const std::string & | destination,
|  | bool | trusted
| ) |  |
| static

Classify the type of hyperlink the destination describes.

Parameters

  destination | The hyperlink destination.
  trusted | Whether we trust the content of this file.

Returns
  HyperlinkType The classification of the link.

Definition at line 165 of file textfile_gui.cpp.

References File, Internal, Unknown, and Web.

Referenced by TextfileWindow::FindHyperlinksInMarkdown(), and TextfileWindow::OnHyperlinkClick().

## ◆ GetTextfile()

std::optional< std::string > GetTextfile | ( | TextfileType | type,
|  | Subdirectory | dir,
|  | std::string_view | filename
| ) |  |

Search a textfile file next to the given content.

Parameters

  type | The type of the textfile to search for.
  dir | The subdirectory to search in.
  filename | The filename of the content to look for.

Returns
  The path to the textfile, `nullptr` otherwise.

Definition at line 939 of file textfile_gui.cpp.

References FioCheckFileExists(), GetCurrentLanguageIsoCode(), and lengthof.

Referenced by GameOptionsWindow::OnInvalidateData().

## ◆ Gunzip()

static std::vector< char > Gunzip | ( | std::span< char > | input | ) |
| static

Do an in-memory gunzip operation.

This works on a raw deflate stream, or a file with gzip or zlib header.

Parameters

  input | Buffer containing the input data.

Returns
  Decompressed buffer.

When decompressing fails, an empty buffer is returned.

Definition at line 780 of file textfile_gui.cpp.

Referenced by TextfileWindow::LoadTextfile().

## ◆ MakeAnchorSlug()

static std::string MakeAnchorSlug | ( | const std::string & | line | ) |
| static

Create a valid slug for the anchor.

Parameters

  line | The line to create the slug for.

Returns
  std::string The slug.

Definition at line 185 of file textfile_gui.cpp.

Referenced by TextfileWindow::AfterLoadMarkdown().

## ◆ Xunzip()

static std::vector< char > Xunzip | ( | std::span< char > | input | ) |
| static

Do an in-memory xunzip operation.

This works on a .xz or (legacy) .lzma file.

Parameters

  input | Buffer containing the input data.

Returns
  Decompressed buffer.

When decompressing fails, an empty buffer is returned.

Definition at line 819 of file textfile_gui.cpp.

Referenced by TextfileWindow::LoadTextfile().

## Variable Documentation

## ◆ _markdown_link_regex

const std::regex _markdown_link_regex {"\\[(.+?)\\]\\‍((.+?)\\‍)", std::regex_constants::ECMAScript | std::regex_constants::optimize}
| static

Regular expression that searches for Markdown links.

Definition at line 148 of file textfile_gui.cpp.

Referenced by TextfileWindow::FindHyperlinksInMarkdown().

## ◆ _nested_textfile_widgets

constexpr std::initializer_list<NWidgetPart> _nested_textfile_widgets
| staticconstexpr

Widgets for the textfile window.

Definition at line 43 of file textfile_gui.cpp.