38Fermer40
Kevin KoflerLe 11/01/2015 à 04:26
GoldenCrystal (./38) :
(Je saute d'un switch à un autre. tongue)
Ça c'est carrément dégueu.

Bah, ça évite soit 2 énormes copiers-collers de blocs entiers, soit si je distribue le if à l'intérieur du switch, un copier-coller du if 9 fois.
(Autre grand classique, le saut dans un if d'erreur.)
On a inventé des langages avec gestion d'exception pour ça, mais admettons. Par contre le code est globalement illisible, donc bof tongue

Bah, c'est plus facile à comprendre si tu as le contexte, j'aurais dû en mettre un peu plus:
        const char * const rss_items[4]={"rss/channel/item/title","rss/channel/item/pubDate","rss/channel/item/dc:creator","/rss/channel/item"};
        const char * const atom_items[4]={"feed/entry/title","feed/entry/issued","feed/entry/author/name","/feed/entry"};
        xmliter_setup(filebuffer,4,is_atom?atom_items:rss_items);
        while ((ret=xmliter_next()) > 0 && nc < MAXNEWS) {
          char *data;
          switch (ret) {

et l'API de xmliter:
// start iterating over buf, looking for the items with the paths given in items
// a path not starting with / is an enter event, a /path is a leave event
void xmliter_setup(const char *buf, unsigned n_items,
                   const char * const *items);

// iterate to the next tag matching one of the desired paths
// returns: >0 (the 1-based index of the item in items) if found
//          0  if the end of buf (terminating \0) was reached with no error
//          <0 (an error code) if an error occurred
int xmliter_next(void);

// returns the data contained in the tag (including subtags), unescaping any
// CDATA or entities discovered, in a buffer allocated with malloc
// unescape_all=1: all characters including &, < and > are unescaped
// unescape_all=0: &, < and > remain escaped to distinguish from nested tags
char *xmliter_data(int unescape_all);

// frees the internal buffers for XML iteration
void xmliter_done(void);