2482 |
24 Apr 11 |
peter |
// $Id$ |
2482 |
24 Apr 11 |
peter |
2 |
|
2482 |
24 Apr 11 |
peter |
3 |
/* |
4252 |
18 Nov 22 |
peter |
Copyright (C) 2011, 2012, 2019, 2020, 2022 Peter Johansson |
2482 |
24 Apr 11 |
peter |
5 |
|
2482 |
24 Apr 11 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
2482 |
24 Apr 11 |
peter |
7 |
|
2482 |
24 Apr 11 |
peter |
The yat library is free software; you can redistribute it and/or |
2482 |
24 Apr 11 |
peter |
modify it under the terms of the GNU General Public License as |
2482 |
24 Apr 11 |
peter |
published by the Free Software Foundation; either version 3 of the |
2482 |
24 Apr 11 |
peter |
License, or (at your option) any later version. |
2482 |
24 Apr 11 |
peter |
12 |
|
2482 |
24 Apr 11 |
peter |
The yat library is distributed in the hope that it will be useful, |
2482 |
24 Apr 11 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2482 |
24 Apr 11 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2482 |
24 Apr 11 |
peter |
General Public License for more details. |
2482 |
24 Apr 11 |
peter |
17 |
|
2482 |
24 Apr 11 |
peter |
You should have received a copy of the GNU General Public License |
2482 |
24 Apr 11 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
2482 |
24 Apr 11 |
peter |
20 |
*/ |
2482 |
24 Apr 11 |
peter |
21 |
|
2881 |
18 Nov 12 |
peter |
22 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
23 |
|
2482 |
24 Apr 11 |
peter |
24 |
#include "GFF2.h" |
2482 |
24 Apr 11 |
peter |
25 |
|
3840 |
13 Aug 19 |
peter |
26 |
#include <cassert> |
2482 |
24 Apr 11 |
peter |
27 |
#include <string> |
2482 |
24 Apr 11 |
peter |
28 |
#include <map> |
2482 |
24 Apr 11 |
peter |
29 |
|
2482 |
24 Apr 11 |
peter |
30 |
namespace theplu { |
2482 |
24 Apr 11 |
peter |
31 |
namespace yat { |
2482 |
24 Apr 11 |
peter |
32 |
namespace omic { |
2482 |
24 Apr 11 |
peter |
33 |
|
2482 |
24 Apr 11 |
peter |
34 |
void GFF2::add_attribute(std::map<std::string, std::string>& m, |
2482 |
24 Apr 11 |
peter |
35 |
const std::string& str) const |
2482 |
24 Apr 11 |
peter |
36 |
{ |
3840 |
13 Aug 19 |
peter |
37 |
size_t offset = str.find_first_not_of(' '); |
3870 |
24 Feb 20 |
peter |
38 |
if (offset == std::string::npos) |
3870 |
24 Feb 20 |
peter |
39 |
return; |
3840 |
13 Aug 19 |
peter |
40 |
size_t i = str.find_first_of(' ', offset); |
3870 |
24 Feb 20 |
peter |
41 |
assert(i != std::string::npos); |
3840 |
13 Aug 19 |
peter |
42 |
assert(i >= offset); |
3840 |
13 Aug 19 |
peter |
43 |
std::string key = str.substr(offset, i-offset); |
3840 |
13 Aug 19 |
peter |
// trim spaces |
3840 |
13 Aug 19 |
peter |
45 |
i = str.find_first_not_of(' ', i+1); |
2482 |
24 Apr 11 |
peter |
// trim off embracing '"' |
2482 |
24 Apr 11 |
peter |
47 |
if (str[i]=='"') |
2482 |
24 Apr 11 |
peter |
48 |
++i; |
3840 |
13 Aug 19 |
peter |
// skip trailing spaces |
3840 |
13 Aug 19 |
peter |
50 |
size_t n = str.find_last_not_of(' '); |
3870 |
24 Feb 20 |
peter |
// skip trailing '"' |
3840 |
13 Aug 19 |
peter |
52 |
if (str[n] == '"') |
2482 |
24 Apr 11 |
peter |
53 |
--n; |
3840 |
13 Aug 19 |
peter |
// str[n] now points to last char we want to include |
4252 |
18 Nov 22 |
peter |
55 |
m[std::move(key)] = str.substr(i,n-i+1); |
2482 |
24 Apr 11 |
peter |
56 |
} |
2482 |
24 Apr 11 |
peter |
57 |
|
2482 |
24 Apr 11 |
peter |
58 |
}}} |