re.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. package po
  5. import (
  6. "regexp"
  7. )
  8. var (
  9. reComment = regexp.MustCompile(`^#`) // #
  10. reExtractedComments = regexp.MustCompile(`^#\.`) // #.
  11. reReferenceComments = regexp.MustCompile(`^#:`) // #:
  12. reFlagsComments = regexp.MustCompile(`^#,`) // #, fuzzy,c-format
  13. rePrevMsgContextComments = regexp.MustCompile(`^#\|\s+msgctxt`) // #| msgctxt
  14. rePrevMsgIdComments = regexp.MustCompile(`^#\|\s+msgid`) // #| msgid
  15. reStringLineComments = regexp.MustCompile(`^#\|\s+".*"\s*$`) // #| "message"
  16. reMsgContext = regexp.MustCompile(`^msgctxt\s+".*"\s*$`) // msgctxt
  17. reMsgId = regexp.MustCompile(`^msgid\s+".*"\s*$`) // msgid
  18. reMsgIdPlural = regexp.MustCompile(`^msgid_plural\s+".*"\s*$`) // msgid_plural
  19. reMsgStr = regexp.MustCompile(`^msgstr\s*".*"\s*$`) // msgstr
  20. reMsgStrPlural = regexp.MustCompile(`^msgstr\s*(\[\d+\])\s*".*"\s*$`) // msgstr[0]
  21. reStringLine = regexp.MustCompile(`^\s*".*"\s*$`) // "message"
  22. reBlankLine = regexp.MustCompile(`^\s*$`) //
  23. )
  24. func (p *Message) isInvalidLine(s string) bool {
  25. if reComment.MatchString(s) {
  26. return false
  27. }
  28. if reBlankLine.MatchString(s) {
  29. return false
  30. }
  31. if reMsgContext.MatchString(s) {
  32. return false
  33. }
  34. if reMsgId.MatchString(s) {
  35. return false
  36. }
  37. if reMsgIdPlural.MatchString(s) {
  38. return false
  39. }
  40. if reMsgStr.MatchString(s) {
  41. return false
  42. }
  43. if reMsgStrPlural.MatchString(s) {
  44. return false
  45. }
  46. if reStringLine.MatchString(s) {
  47. return false
  48. }
  49. return true
  50. }