Simplified Rust code to use += operator instead of String.push_str().
This commit is contained in:
parent
390198ea4b
commit
ede63e8538
|
@ -238,13 +238,13 @@ impl QrCode {
|
|||
pub fn to_svg_string(&self, border: i32) -> String {
|
||||
assert!(border >= 0, "Border must be non-negative");
|
||||
let mut result: String = String::new();
|
||||
result.push_str("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
||||
result.push_str("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
|
||||
result += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
result += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
||||
let dimension = self.size.checked_add(border.checked_mul(2).unwrap()).unwrap();
|
||||
result.push_str(&format!(
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 {0} {0}\" stroke=\"none\">\n", dimension));
|
||||
result.push_str("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n");
|
||||
result.push_str("\t<path d=\"");
|
||||
result += &format!(
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 {0} {0}\" stroke=\"none\">\n", dimension);
|
||||
result += "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
|
||||
result += "\t<path d=\"";
|
||||
let mut head: bool = true;
|
||||
for y in -border .. self.size + border {
|
||||
for x in -border .. self.size + border {
|
||||
|
@ -252,14 +252,14 @@ impl QrCode {
|
|||
if head {
|
||||
head = false;
|
||||
} else {
|
||||
result.push_str(" ");
|
||||
result += " ";
|
||||
}
|
||||
result.push_str(&format!("M{},{}h1v1h-1z", x + border, y + border));
|
||||
result += &format!("M{},{}h1v1h-1z", x + border, y + border);
|
||||
}
|
||||
}
|
||||
}
|
||||
result.push_str("\" fill=\"#000000\"/>\n");
|
||||
result.push_str("</svg>\n");
|
||||
result += "\" fill=\"#000000\"/>\n";
|
||||
result += "</svg>\n";
|
||||
result
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue