Skip to content

Commit 91ead1e

Browse files
committed
deploy: f0e8d44
1 parent aaa41b7 commit 91ead1e

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

dev/src/uu_nl/nl.rs.html

+64-12
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,32 @@
424424
<a href="#424" id="424">424</a>
425425
<a href="#425" id="425">425</a>
426426
<a href="#426" id="426">426</a>
427+
<a href="#427" id="427">427</a>
428+
<a href="#428" id="428">428</a>
429+
<a href="#429" id="429">429</a>
430+
<a href="#430" id="430">430</a>
431+
<a href="#431" id="431">431</a>
432+
<a href="#432" id="432">432</a>
433+
<a href="#433" id="433">433</a>
434+
<a href="#434" id="434">434</a>
435+
<a href="#435" id="435">435</a>
436+
<a href="#436" id="436">436</a>
437+
<a href="#437" id="437">437</a>
438+
<a href="#438" id="438">438</a>
439+
<a href="#439" id="439">439</a>
440+
<a href="#440" id="440">440</a>
441+
<a href="#441" id="441">441</a>
442+
<a href="#442" id="442">442</a>
443+
<a href="#443" id="443">443</a>
444+
<a href="#444" id="444">444</a>
445+
<a href="#445" id="445">445</a>
446+
<a href="#446" id="446">446</a>
447+
<a href="#447" id="447">447</a>
448+
<a href="#448" id="448">448</a>
449+
<a href="#449" id="449">449</a>
450+
<a href="#450" id="450">450</a>
451+
<a href="#451" id="451">451</a>
452+
<a href="#452" id="452">452</a>
427453
</pre></div><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
428454
// *
429455
// * (c) Tobias Bohumir Schottdorf &lt;tobias.schottdorf@gmail.com&gt;
@@ -689,13 +715,8 @@
689715
</span><span class="kw">fn </span>nl&lt;T: Read&gt;(reader: <span class="kw-2">&amp;mut </span>BufReader&lt;T&gt;, settings: <span class="kw-2">&amp;</span>Settings) -&gt; UResult&lt;()&gt; {
690716
<span class="kw">let </span>regexp: regex::Regex = regex::Regex::new(<span class="string">r&quot;.?&quot;</span>).unwrap();
691717
<span class="kw">let </span><span class="kw-2">mut </span>line_no = settings.starting_line_number;
692-
<span class="comment">// The current line number&#39;s width as a string. Using to_string is inefficient
693-
// but since we only do it once, it should not hurt.
694-
</span><span class="kw">let </span><span class="kw-2">mut </span>line_no_width = line_no.to_string().len();
718+
<span class="kw">let </span><span class="kw-2">mut </span>line_no_width = line_no.len();
695719
<span class="kw">let </span>line_no_width_initial = line_no_width;
696-
<span class="comment">// Stores the smallest integer with one more digit than line_no, so that
697-
// when line_no &gt;= line_no_threshold, we need to use one more digit.
698-
</span><span class="kw">let </span><span class="kw-2">mut </span>line_no_threshold = <span class="number">10i64</span>.pow(line_no_width <span class="kw">as </span>u32);
699720
<span class="kw">let </span><span class="kw-2">mut </span>empty_line_count: u64 = <span class="number">0</span>;
700721
<span class="kw">let </span>fill_char = <span class="kw">match </span>settings.number_format {
701722
NumberFormat::RightZero =&gt; <span class="string">&#39;0&#39;</span>,
@@ -757,7 +778,6 @@
757778
</span><span class="kw">if </span>settings.renumber {
758779
line_no = settings.starting_line_number;
759780
line_no_width = line_no_width_initial;
760-
line_no_threshold = <span class="number">10i64</span>.pow(line_no_width <span class="kw">as </span>u32);
761781
}
762782
<span class="kw-2">&amp;</span>settings.header_numbering
763783
}
@@ -826,11 +846,7 @@
826846
<span class="comment">// Now update the variables for the (potential) next
827847
// line.
828848
</span>line_no += settings.line_increment;
829-
<span class="kw">while </span>line_no &gt;= line_no_threshold {
830-
<span class="comment">// The line number just got longer.
831-
</span>line_no_threshold <span class="kw-2">*</span>= <span class="number">10</span>;
832-
line_no_width += <span class="number">1</span>;
833-
}
849+
line_no_width = line_no.len();
834850
}
835851
<span class="prelude-val">Ok</span>(())
836852
}
@@ -850,4 +866,40 @@
850866
<span class="kw">fn </span>pass_all(<span class="kw">_</span>: <span class="kw-2">&amp;</span>str, <span class="kw">_</span>: <span class="kw-2">&amp;</span>regex::Regex) -&gt; bool {
851867
<span class="bool-val">true
852868
</span>}
869+
870+
<span class="kw">trait </span>Length {
871+
<span class="kw">fn </span>len(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; usize;
872+
}
873+
874+
<span class="kw">impl </span>Length <span class="kw">for </span>i64 {
875+
<span class="comment">// Returns the length in `char`s.
876+
</span><span class="kw">fn </span>len(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; usize {
877+
<span class="kw">if </span><span class="kw-2">*</span><span class="self">self </span>== <span class="number">0 </span>{
878+
<span class="kw">return </span><span class="number">1</span>;
879+
};
880+
881+
<span class="kw">let </span>sign_len = <span class="kw">if </span><span class="kw-2">*</span><span class="self">self </span>&lt; <span class="number">0 </span>{ <span class="number">1 </span>} <span class="kw">else </span>{ <span class="number">0 </span>};
882+
(<span class="number">0</span>..).take_while(|i| <span class="number">10i64</span>.pow(<span class="kw-2">*</span>i) &lt;= <span class="self">self</span>.abs()).count() + sign_len
883+
}
884+
}
885+
886+
<span class="attr">#[cfg(test)]
887+
</span><span class="kw">mod </span>test {
888+
<span class="kw">use super</span>::<span class="kw-2">*</span>;
889+
890+
<span class="attr">#[test]
891+
</span><span class="kw">fn </span>test_len() {
892+
<span class="macro">assert_eq!</span>((-<span class="number">1</span>).len(), <span class="number">2</span>);
893+
<span class="macro">assert_eq!</span>((-<span class="number">10</span>).len(), <span class="number">3</span>);
894+
<span class="macro">assert_eq!</span>((-<span class="number">100</span>).len(), <span class="number">4</span>);
895+
<span class="macro">assert_eq!</span>((-<span class="number">1000</span>).len(), <span class="number">5</span>);
896+
897+
<span class="macro">assert_eq!</span>(<span class="number">0</span>.len(), <span class="number">1</span>);
898+
899+
<span class="macro">assert_eq!</span>(<span class="number">1</span>.len(), <span class="number">1</span>);
900+
<span class="macro">assert_eq!</span>(<span class="number">10</span>.len(), <span class="number">2</span>);
901+
<span class="macro">assert_eq!</span>(<span class="number">100</span>.len(), <span class="number">3</span>);
902+
<span class="macro">assert_eq!</span>(<span class="number">1000</span>.len(), <span class="number">4</span>);
903+
}
904+
}
853905
</code></pre></div></section></main></body></html>

dev/uu_nl/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `uu_nl` crate."><title>uu_nl - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-f3501f0f5ae15dfb.css" id="mainThemeStyle"><div id="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="uu_nl" data-themes="" data-resource-suffix="" data-rustdoc-version="1.71.0 (8ede3aae2 2023-07-12)" data-search-js="search-4926e5fc22a5646a.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-0f8c037637f9eb3e.css" data-theme-dark-css="dark-1097f8e92a01e3cf.css" data-theme-ayu-css="ayu-614652228113ac93.css" ></div><script src="../static.files/storage-62ce34ea385b278a.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-f0540c1d82cde29b.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-0f8c037637f9eb3e.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-1097f8e92a01e3cf.css"><link rel="stylesheet" href="../static.files/noscript-13285aec31fa243e.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="logo-container" href="../uu_nl/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../uu_nl/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2 class="location"><a href="#">Crate uu_nl</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.0.20</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">uu_nl</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/uu_nl/nl.rs.html#9-426">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="options/index.html" title="mod uu_nl::options">options</a></div></li></ul><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Settings.html" title="struct uu_nl::Settings">Settings</a></div></li></ul><h2 id="functions" class="small-section-header"><a href="#functions">Functions</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.uu_app.html" title="fn uu_nl::uu_app">uu_app</a></div></li><li><div class="item-name"><a class="fn" href="fn.uumain.html" title="fn uu_nl::uumain">uumain</a></div></li></ul></section></div></main></body></html>
1+
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `uu_nl` crate."><title>uu_nl - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-f3501f0f5ae15dfb.css" id="mainThemeStyle"><div id="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="uu_nl" data-themes="" data-resource-suffix="" data-rustdoc-version="1.71.0 (8ede3aae2 2023-07-12)" data-search-js="search-4926e5fc22a5646a.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-0f8c037637f9eb3e.css" data-theme-dark-css="dark-1097f8e92a01e3cf.css" data-theme-ayu-css="ayu-614652228113ac93.css" ></div><script src="../static.files/storage-62ce34ea385b278a.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-f0540c1d82cde29b.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-0f8c037637f9eb3e.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-1097f8e92a01e3cf.css"><link rel="stylesheet" href="../static.files/noscript-13285aec31fa243e.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="logo-container" href="../uu_nl/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../uu_nl/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2 class="location"><a href="#">Crate uu_nl</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.0.20</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">uu_nl</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/uu_nl/nl.rs.html#9-452">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="options/index.html" title="mod uu_nl::options">options</a></div></li></ul><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Settings.html" title="struct uu_nl::Settings">Settings</a></div></li></ul><h2 id="functions" class="small-section-header"><a href="#functions">Functions</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.uu_app.html" title="fn uu_nl::uu_app">uu_app</a></div></li><li><div class="item-name"><a class="fn" href="fn.uumain.html" title="fn uu_nl::uumain">uumain</a></div></li></ul></section></div></main></body></html>

0 commit comments

Comments
 (0)