Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: kernel_include.py: move apply_range() and add a docstring

While not required, better to have caller functions at the end.
As apply_range() is now called by xref_text(), move it to be
before the latter.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/a6ce0fd7c03a01338753fd81ed0c4631f78311d6.1755872208.git.mchehab+huawei@kernel.org

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
01dba168 4ad9cabc

+36 -32
+36 -32
Documentation/sphinx/kernel_include.py
··· 113 113 except UnicodeError as error: 114 114 raise self.severe('Problem with directive:\n%s' % ErrorString(error)) 115 115 116 + def apply_range(self, rawtext): 117 + """ 118 + Handles start-line, end-line, start-after and end-before parameters 119 + """ 120 + 121 + # Get to-be-included content 122 + startline = self.options.get('start-line', None) 123 + endline = self.options.get('end-line', None) 124 + try: 125 + if startline or (endline is not None): 126 + lines = rawtext.splitlines() 127 + rawtext = '\n'.join(lines[startline:endline]) 128 + except UnicodeError as error: 129 + raise self.severe(f'Problem with "{self.name}" directive:\n' 130 + + io.error_string(error)) 131 + # start-after/end-before: no restrictions on newlines in match-text, 132 + # and no restrictions on matching inside lines vs. line boundaries 133 + after_text = self.options.get("start-after", None) 134 + if after_text: 135 + # skip content in rawtext before *and incl.* a matching text 136 + after_index = rawtext.find(after_text) 137 + if after_index < 0: 138 + raise self.severe('Problem with "start-after" option of "%s" ' 139 + "directive:\nText not found." % self.name) 140 + rawtext = rawtext[after_index + len(after_text) :] 141 + before_text = self.options.get("end-before", None) 142 + if before_text: 143 + # skip content in rawtext after *and incl.* a matching text 144 + before_index = rawtext.find(before_text) 145 + if before_index < 0: 146 + raise self.severe('Problem with "end-before" option of "%s" ' 147 + "directive:\nText not found." % self.name) 148 + rawtext = rawtext[:before_index] 149 + 150 + return rawtext 151 + 116 152 def xref_text(self, env, path, tab_width): 117 153 """ 118 154 Read and add contents from a C file parsed to have cross references. ··· 198 162 self.state_machine.insert_input(result, path) 199 163 200 164 return [] 201 - 202 - def apply_range(self, rawtext): 203 - # Get to-be-included content 204 - startline = self.options.get('start-line', None) 205 - endline = self.options.get('end-line', None) 206 - try: 207 - if startline or (endline is not None): 208 - lines = rawtext.splitlines() 209 - rawtext = '\n'.join(lines[startline:endline]) 210 - except UnicodeError as error: 211 - raise self.severe(f'Problem with "{self.name}" directive:\n' 212 - + io.error_string(error)) 213 - # start-after/end-before: no restrictions on newlines in match-text, 214 - # and no restrictions on matching inside lines vs. line boundaries 215 - after_text = self.options.get("start-after", None) 216 - if after_text: 217 - # skip content in rawtext before *and incl.* a matching text 218 - after_index = rawtext.find(after_text) 219 - if after_index < 0: 220 - raise self.severe('Problem with "start-after" option of "%s" ' 221 - "directive:\nText not found." % self.name) 222 - rawtext = rawtext[after_index + len(after_text) :] 223 - before_text = self.options.get("end-before", None) 224 - if before_text: 225 - # skip content in rawtext after *and incl.* a matching text 226 - before_index = rawtext.find(before_text) 227 - if before_index < 0: 228 - raise self.severe('Problem with "end-before" option of "%s" ' 229 - "directive:\nText not found." % self.name) 230 - rawtext = rawtext[:before_index] 231 - 232 - return rawtext 233 165 234 166 def literal(self, path, tab_width, rawtext): 235 167 """Output a literal block"""