...

Source file src/github.com/chai2010/gettext-go/po/re.go

Documentation: github.com/chai2010/gettext-go/po

     1  // Copyright 2013 ChaiShushan <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package po
     6  
     7  import (
     8  	"regexp"
     9  )
    10  
    11  var (
    12  	reComment                = regexp.MustCompile(`^#`)              // #
    13  	reExtractedComments      = regexp.MustCompile(`^#\.`)            // #.
    14  	reReferenceComments      = regexp.MustCompile(`^#:`)             // #:
    15  	reFlagsComments          = regexp.MustCompile(`^#,`)             // #, fuzzy,c-format
    16  	rePrevMsgContextComments = regexp.MustCompile(`^#\|\s+msgctxt`)  // #| msgctxt
    17  	rePrevMsgIdComments      = regexp.MustCompile(`^#\|\s+msgid`)    // #| msgid
    18  	reStringLineComments     = regexp.MustCompile(`^#\|\s+".*"\s*$`) // #| "message"
    19  
    20  	reMsgContext   = regexp.MustCompile(`^msgctxt\s+".*"\s*$`)            // msgctxt
    21  	reMsgId        = regexp.MustCompile(`^msgid\s+".*"\s*$`)              // msgid
    22  	reMsgIdPlural  = regexp.MustCompile(`^msgid_plural\s+".*"\s*$`)       // msgid_plural
    23  	reMsgStr       = regexp.MustCompile(`^msgstr\s*".*"\s*$`)             // msgstr
    24  	reMsgStrPlural = regexp.MustCompile(`^msgstr\s*(\[\d+\])\s*".*"\s*$`) // msgstr[0]
    25  	reStringLine   = regexp.MustCompile(`^\s*".*"\s*$`)                   // "message"
    26  	reBlankLine    = regexp.MustCompile(`^\s*$`)                          //
    27  )
    28  
    29  func (p *Message) isInvalidLine(s string) bool {
    30  	if reComment.MatchString(s) {
    31  		return false
    32  	}
    33  	if reBlankLine.MatchString(s) {
    34  		return false
    35  	}
    36  
    37  	if reMsgContext.MatchString(s) {
    38  		return false
    39  	}
    40  	if reMsgId.MatchString(s) {
    41  		return false
    42  	}
    43  	if reMsgIdPlural.MatchString(s) {
    44  		return false
    45  	}
    46  	if reMsgStr.MatchString(s) {
    47  		return false
    48  	}
    49  	if reMsgStrPlural.MatchString(s) {
    50  		return false
    51  	}
    52  
    53  	if reStringLine.MatchString(s) {
    54  		return false
    55  	}
    56  
    57  	return true
    58  }
    59  

View as plain text