My snippet for code snippet competition
http://www.daniweb.com/software-development/python/code/426990/split-string-except-inside-brackets-or-quotes
is completely messed up. System clitch?

Recommended Answers

All 15 Replies

Please define "messed up"? The code highlighting is off, you mean?

It looks like the HTML entities weren't properly converted for display.

From what I can tell, it was typed in that way.

""" for example has become """ in the snippet. Here the original, I will of course replace it again, but wanted to give you chance to look at what happened before restoring it.

Hmmm... Check http://www.daniweb.com/search/query//0?q=site%3A*%2F+%26quot%3B

def splitq (seq, sep=None, pairs=("()", "[]", "{}"), quote='"\'') :
    """Split seq by sep but considering parts inside pairs or quoted as unbreakable
       pairs have diferent start and end value, quote have same symbol in beginning and end
       use itertools.islice if you want only part of splits

    """
    if not seq:
        yield []
    else:
        lsep = len(sep) if sep is not None else 1
        lpair, rpair = zip(*pairs)
        pairs = dict(pairs)
        start = index = 0
        while 0 <= index < len(seq):
            c = seq[index]
            #print index, c
            if (sep and seq[index:].startswith(sep)) or (sep is None and c.isspace()):
                yield seq[start:index]
                #pass multiple separators as single one
                if sep is None:
                    index = len(seq) - len(seq[index:].lstrip())
                    #if index < len(seq):
                    #    print(repr(seq[index]),index)
                else:
                    while (sep and seq[index:].startswith(sep)):
                        index = index + lsep
                start = index

            elif c in quote:
                index += 1
                p, index = index, seq.find(c,index) + 1
                if not index:
                    raise IndexError('Unmatched quote %r\n%i:%s' % (c, p, seq[:p]))
            elif c in lpair:
                nesting = 1
                while True:
                    index += 1
                    p, index = index, seq.find(pairs[c], index)
                    if index < 0:
                        raise IndexError('Did not find end of pair for %r: %r\n%i:%s' % (c, pairs[c], p, seq[:p]))
                    nesting += '{lpair}({inner})'.format(lpair=c, inner=splitq(seq[p:index].count(c) - 2))
                    if not nesting:
                        break

            else:
                index += 1
        if seq[start:]:
            yield seq[start:]


for test in ("Hello, (Tony 'pyTony' Jarkko Veijalainen)  \t\n {'This \'is\' quoted' Great to \"split\" this} split \"Also Quoted part\" [test test] end ",
                "Hello, (Tony Jarkko Veijalainen)         \"This (\"is\") quoted\" Great to \"split\"   {this split} \"Also Quoted part\" [test test] end ",
                "Hello, (Tony Jarkko Veijalainen This (\"is\")' quoted Great, to split this split \"Also Quoted part\"       [test split test] end ",
                "Hello, [Tony Jarkko Veijalainen) \"This (\"is\") quoted\" Great, to split this split \"Also Quoted part\" test split test end ",
                '(An (even better)) [Lisp Interpreter [in Python]] '):
    print('-' * len(test))
    print(repr(test))
    try:
        print('\n'.join(splitq(test)))
    except IndexError as e:
        print(e)

Tony, I tried creating a test snippet and was unable to duplicate the problem. It looks like it was typed in with the &quot; ?? I'm confused. DECEPTIKON?!

If it's an intermittent problem, it seems pretty rare given a glance at the most recent snippets. I strongly doubt that the code was posted that way even unintentionally, but without solid reproduction of the issue there's not a whole lot I can suggest beyond keeping an eye out for future instances whenever someone posts a snippet.

I can not imagine how it would happen in client side, hope it has not been since the last update. Beginning at least it showed OK. I repasted the code in the code box "destroying the evidence".

Member Avatar for iamthwee

I reported this also...

See:
http://www.daniweb.com/community-center/daniweb-community-feedback/threads/433942/user-profiles

The code snippet dates back to june 2012 I'm guessing when daniweb was using the old vbulletin.

There's no way pyTony would have typed that in accidently. Recreating it now shows it isn't an issue.

I would wager lots of threads or posts before migrating to the 'NEW' Daniweb board probably exhibits the same issues. As shown by the search link pyTony posted, although it appears rather randomly.

It might be worth checking it out, in fact it's pretty obvious IMO you guys messed up the import as there is no way that many MEMBERS would accidently be typing html entities instead of the real ones.

If it's not a code import mess up (check actual mysql enteries) then how you are rendering the html is causing something funky.
Could even be a codeIgniter quirk?

Member Avatar for iamthwee

This definitely needs sorting as a lot of legacy old code maybe rendered unusable!

Thanks

Member Avatar for iamthwee

Hmm, maybe it just occurs when the OP wrongly used <code></code> tags instead of [code][/code] tags so it might not be so bad.

Although this:

Looks highly suspicious and doesn't have <code></code> tags?

No, the code is in Code Snippet separate frame for code and we are now using Markdown, not BBcode. And the Board change happened end of spring.

The code snippet dates back to june 2012 I'm guessing when daniweb was using the old vbulletin.

The switchover was in mid March, but I won't deny that there were growing pains as we shook out bugs. This issue may be a combination of migrating BBCode to Markdown and a bug that was fixed around June.

As with any formatting problems, feel free to report them so that they can be fixed by a moderator. And if you can find a recent instance of this issue (say from August 2012 forward), that would be helpful in identifying a current bug rather than something we've already fixed but haven't cleared out all of the casualties.

Well my snippet was 2nd of July, but my revised version which I updated as moderator is dated 10th of July in my computer. So not quite August.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.