The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Selector.vala in libsvgbird

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libsvgbird/Selector.vala.
Merge ../birdfont-2.x
1 /* 2 Copyright (C) 2016 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 using B; 16 using Math; 17 18 namespace SvgBird { 19 20 public class Selector : GLib.Object { 21 22 Gee.ArrayList<SelectorPattern> patterns = new Gee.ArrayList<SelectorPattern> (); 23 public SvgStyle style { get; set; } 24 25 public Selector (string pattern, SvgStyle style) { 26 string[] selector_patterns = pattern.split (","); 27 28 for (int i = 0; i < selector_patterns.length; i++) { 29 patterns.add (new SelectorPattern (selector_patterns[i])); 30 } 31 32 this.style = style; 33 } 34 35 public Selector.copy_constructor (Selector selector) { 36 style = selector.style.copy (); 37 38 foreach (SelectorPattern pattern in selector.patterns) { 39 patterns.add (pattern.copy ()); 40 } 41 } 42 43 public string to_string () { 44 StringBuilder s = new StringBuilder (); 45 46 foreach (SelectorPattern pattern in patterns) { 47 if (s.str != "") { 48 s.append (", "); 49 } 50 51 s.append (pattern.to_string ()); 52 } 53 54 return s.str; 55 } 56 57 public Selector copy () { 58 return new Selector.copy_constructor (this); 59 } 60 61 public bool match (XmlElement tag, string? id, string? css_class) { 62 foreach (SelectorPattern pattern in patterns) { 63 if (pattern.match (tag, id, css_class)) { 64 return true; 65 } 66 } 67 68 return false; 69 } 70 } 71 72 } 73