xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
Commit 746560420021d148c58578af77c9f7bb05cc5918

Added a custom csv line parsing (partial) for when the program will be re-written in C
Author: Catalin(ux) M. BOIE
Author date (UTC): 2017-03-02 17:53
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2017-03-02 17:53
Parent(s): 214dfb3cd1c7e5a3b5a0353a4c9f9b63cb6545f2
Signing key:
Tree: 0925baff4075e4e6428212706efd3051d463217c
File Lines added Lines deleted
misc/compare.php 84 0
File misc/compare.php changed (mode: 100644) (index f1a68b2..056f6e1)
3 3 // compare.csv is easy edited with LibreOffice // compare.csv is easy edited with LibreOffice
4 4 // compare.html gets included in the website // compare.html gets included in the website
5 5
6 /*
7 * Returns an array with fields
8 * Parses something like: "a,a",,"b","c" => array('a,a', '', 'b', 'c')
9 */
10 /*
11 function parse_csv_line($line)
12 {
13 $ret = array();
14 $pos = 0;
15 $f = '';
16 $first = TRUE;
17 $len = strlen($line);
18 $last_was_comma = FALSE;
19 while (1) {
20 //echo "REST: " . substr($line, $pos) . "\n";
21 if (strncmp($line[$pos], '"', 1) == 0) {
22 $q = strpos($line, '"', $pos + 1);
23 //echo "Q q=" . $q . "\n";
24 if ($q === FALSE) {
25 echo 'Line: ' . $line . ' is malformed (unterminated quoted string)!' . "\n";
26 return FALSE;
27 }
28 $ret[] = substr($line, $pos + 1, $q - $pos - 1);
29 $pos = $q + 1;
30
31 if ($pos == $len)
32 break;
33
34 if (strncmp($line[$pos], ',', 1) != 0) {
35 echo 'Line: ' . $line . ' is malformed (no comma after quote)!' . "\n";
36 return FALSE;
37 }
38
39 $pos++; // skip comma
40 } else {
41 // This field does not start with '"' => starts with a comma! Search till next ','
42 $q = strpos($line, ',', $pos);
43 //echo "X q=" . $q . "\n";
44 if ($q === FALSE) {
45 // Final element after last ','
46 $ret[] = substr($line, $pos);
47 break;
48 }
49
50 $last_was_comma = TRUE;
51 $ret[] = substr($line, $pos, $q - $pos);
52 $pos = $q + 1;
53 if ($pos == $len)
54 break;
55 }
56 }
57
58 if ($last_was_comma)
59 $ret[] = '';
60
61 return $ret;
62 }
63
64 $s = 'a';
65 $r = parse_csv_line($s);
66 echo $s . ':'; print_r($r);
67
68 $s = ',b';
69 $r = parse_csv_line($s);
70 echo $s . ':'; print_r($r);
71
72 $s = '"a","b","c';
73 $r = parse_csv_line($s);
74 echo $s . ':'; print_r($r);
75
76 $s = '"a","b","c"';
77 $r = parse_csv_line($s);
78 echo $s . ':'; print_r($r);
79
80 $s = ',"a,a","b 3 6,6","c d e c",,';
81 $r = parse_csv_line($s);
82 echo $s . ':'; print_r($r);
83
84 $s = '"a",,';
85 $r = parse_csv_line($s);
86 echo $s . ':'; print_r($r);
87 exit(1);
88 */
89
6 90 $INC = dirname(__FILE__) . '/../inc'; $INC = dirname(__FILE__) . '/../inc';
7 91 require_once($INC . '/util.inc.php'); require_once($INC . '/util.inc.php');
8 92
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master