1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// SPDX-FileCopyrightText: 2024 Shun Sakai
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! The `is-svg` crate is a library for testing whether a given data is a [SVG]
//! image.
//!
//! This crate assumes the given data to be a valid SVG image if
//! [`usvg::Tree::from_data`] returns [`Ok`], and an invalid SVG image if it
//! returns [`Err`]. It supports both a SVG string and a [gzip-compressed] SVG
//! data.
//!
//! # Examples
//!
//! ```
//! assert_eq!(
//! is_svg::is_svg(include_str!("../tests/data/w3/svg-logo-v.svg")),
//! true
//! );
//! assert_eq!(
//! is_svg::is_svg(include_bytes!("../tests/data/w3/svg-logo-v.png")),
//! false
//! );
//!
//! // `.svgz` is also supported.
//! assert_eq!(
//! is_svg::is_svg(include_bytes!("../tests/data/w3/svg-logo-v.svgz")),
//! true
//! );
//! ```
//!
//! [SVG]: https://www.w3.org/Graphics/SVG/
//! [gzip-compressed]: https://datatracker.ietf.org/doc/html/rfc1952
// Lint levels of rustc.
use ;
/// Magic number of gzip defined in [RFC 1952].
///
/// [RFC 1952]: https://datatracker.ietf.org/doc/html/rfc1952
const GZIP_MAGIC_NUMBER: = ;
/// Returns [`true`] if `data` is a valid [SVG] data, and [`false`] otherwise.
///
/// This function also supports the [gzip-compressed] SVG image (`.svgz`).
///
/// # Examples
///
/// ```
/// assert_eq!(
/// is_svg::is_svg(include_str!("../tests/data/w3/svg-logo-v.svg")),
/// true
/// );
/// assert_eq!(
/// is_svg::is_svg(include_bytes!("../tests/data/w3/svg-logo-v.png")),
/// false
/// );
///
/// assert_eq!(
/// is_svg::is_svg(include_bytes!("../tests/data/w3/svg-logo-v.svgz")),
/// true
/// );
/// ```
///
/// [SVG]: https://www.w3.org/Graphics/SVG/
/// [gzip-compressed]: https://datatracker.ietf.org/doc/html/rfc1952
/// Returns [`true`] if `data` is a valid non [gzip-compressed] [SVG] data
/// (`.svg`), and [`false`] otherwise.
///
/// This function returns [`false`] if `data` is a valid SVG data, but
/// gzip-compressed (`.svgz`).
///
/// # Examples
///
/// ```
/// assert_eq!(
/// is_svg::is_svg_string(include_str!("../tests/data/w3/svg-logo-v.svg")),
/// true
/// );
/// assert_eq!(
/// is_svg::is_svg_string(include_bytes!("../tests/data/w3/svg-logo-v.png")),
/// false
/// );
///
/// assert_eq!(
/// is_svg::is_svg_string(include_bytes!("../tests/data/w3/svg-logo-v.svgz")),
/// false
/// );
/// ```
///
/// [gzip-compressed]: https://datatracker.ietf.org/doc/html/rfc1952
/// [SVG]: https://www.w3.org/Graphics/SVG/
/// Returns [`true`] if `data` is a valid [gzip-compressed] [SVG] data
/// (`.svgz`), and [`false`] otherwise.
///
/// This function returns [`false`] if `data` is a valid SVG data, but non
/// gzip-compressed (`.svg`).
///
/// # Examples
///
/// ```
/// assert_eq!(
/// is_svg::is_svgz(include_bytes!("../tests/data/w3/svg-logo-v.svgz")),
/// true
/// );
/// assert_eq!(
/// is_svg::is_svgz(include_bytes!("../tests/data/w3/svg-logo-v.png")),
/// false
/// );
///
/// assert_eq!(
/// is_svg::is_svgz(include_str!("../tests/data/w3/svg-logo-v.svg")),
/// false
/// );
/// ```
///
/// [gzip-compressed]: https://datatracker.ietf.org/doc/html/rfc1952
/// [SVG]: https://www.w3.org/Graphics/SVG/